The table view works fine however when I leave the view and come back to it the second time, I get a memory leak. Probably something in the viewDidLoad just not sure.
I
You have several places where you call [[XXX alloc] init]
where XXX is a NSMutableArray
or NSMutableString
. You never release these and they are not autoreleased, thus they leak.
I heard the
[UIImage imageNamed:@"contact.png"];
is a memory occurring line. It will create an autorelease object as the returned object. May be that can also be a problem.
In tableView:didSelectRowAtIndexPath:
, lastIndexPath
is not released before it retains indexPath
. In viewDidLoad
, you nil
out the variables without releasing them.
And in XML parsing, you create and release strings based on the assumption that one element doesn't contain the other. If they are nested, one element will start before the other ends. In such case, you lose the reference to the original string and thus leak. This is not much of an issue if they are siblings but by the looks of you log, the elements are nested.
I see most of your statement are ready for leak, e.g in the viewDidUnload method , you are not releasing any instance member properly.
you need to call release on the object which you either alloced, init or retain.
(void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
[remoteRecipientItems release];
remoteRecipientItems = nil;
[remoteRecipientID release];
remoteRecipientID = nil;
..................
..................
}
Would suggest you to spend some time to read Memory Management Programming Guide
Please see my response here: Deallocating and removing UiButtons
It contains an explanation of when you should retain/release or rely on autorelease. Apply these rules to your code above. In short, anytime you alloc anything, you should be following it with a call to release on that object. If you don't, you'll have a memory leak.
Update:
You're not releasing the activityIndicator that you create here.
- (void)viewDidLoad {
[super viewDidLoad];
// ...
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
// ...
[self.view addSubview:activityIndicator];
}