releasing static instance

Discussion in 'Mac Programming' started by shilpa, Jul 1, 2008.

  1. shilpa macrumors member

    May 29, 2008
    Hi all,
    in my app i have created static instance of catalog object.
    +(Catalog *)getCatalogObject
    if(staticCatalogObj == nil)
    staticCatalogObj = [[Catalog alloc]init];
    staticCatalogObj.catalogDictionary = [[NSMutableDictionary alloc] init];
    staticCatalogObj.itemsArray = [[NSMutableArray alloc]init];

    return staticCatalogObj;
    how to release this catalog object now.

    also if any class has property then do we need to release them,or only if we release the instance is fine.for ex

    @interface items : NSObject {
    NSString *productID;
    NSString *vendorID;
    NSString *itemPrice;
    NSString *itemName;
    NSString *itemDescrioption;
    NSString *smallImage;
    NSString *bigImage;
    NSInteger quantity;
    @property(nonatomic)NSInteger quantity;
    @property(nonatomic,copy)NSString *productID;
    @property(nonatomic,copy)NSString *vendorID;
    @property(nonatomic,copy)NSString *itemPrice;
    @property(nonatomic,copy)NSString *itemName;
    @property(nonatomic,copy)NSString *itemDescrioption;
    @property(nonatomic,copy)NSString *smallImage;
    @property(nonatomic,copy)NSString *bigImage;

    items *itemObject = [[items alloc]init];
    itemObject.productID = @"565";

    then do i need to do
    [itemObject.productID release];

    i have not writen dealloc function for this class.
  2. HiRez macrumors 603


    Jan 6, 2004
    Western US
    You need to hold onto a reference for that allocated object somewhere, probably in your application controller object. Then you can call release on it (or do it through the accessor). I'm assuming you're not using garbage collection...

Share This Page