Im very confused with the memory management.
Declared variable allNoticeArray in .h file:
@interface NoticeViewController : UITableViewController
{
NSMutableArray *allNoticeArray;
}
@property (nonatomic, retain) NSMutableArray *allNoticeArray;
@end
Alloc and init the variable in .m file:
@implementation NoticeViewController
@synthesize allNoticeArray;
- (void)viewDidLoad
{
[super viewDidLoad];
self.allNoticeArray = [[[NSMutableArray alloc] init] autorelease];
}
- (void)dealloc
{
[super dealloc];
/*
***should I release allNoticeArray here or not?***
*/
//[allNoticeArray release];
}
Should I release the allNoticeArray in dealloc function or not?
Thank you in advance!
It looks like you're manually managing your memory rather than using ARC.
If you're using IOS5 it might be easier for you to convert your project to ARC, then you won't have to worry about dealloc in this context.
If you don't want to use ARC you do need to release it in this context because you alloc'd it in viewDidLoad. You might also be interested in this article about dealloc.
Yes, you have to release the object. You could do the below in your dealloc method which will release your object.
self.allNoticeArray = nil;
REASON: Although you have autoreleased the array you have declared your property as retain. So the object will be retained and used. So to totally remove the object from memory you should again call release over it. You can learn everything about memory management here https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With