PDA

View Full Version : releasing static instance




shilpa
Jul 1, 2008, 11:38 PM
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.



HiRez
Jul 2, 2008, 01:13 AM
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...