views:

46

answers:

2

In my 'cellForRowAtIndexPath' method for a UITableView delegate, I'm allocating a cell if it doesn't exist, and in this cell, I'm creating a new activity spinner like so:

UIActivityIndicatorView *actView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray ] autorelease];

I'm using Leaks to detect memory leaks in my program, and for some reason, this is coming up as a leak, even though it's autoreleasing. The cell itself is also autoreleasing. Has anyone had experience with autoreleasing variables coming up as leaks in the Leaks instrument, and how to tackle these problems?

This is only leaking if I add it to the cell's contentView. If I just create it and let it be, the Leak instrument doesn't report any problem.

Also, if it helps, this is the history Leaks is displaying for this memory location. It looks like it at some point gets an additional retain message? This is not being done in my code.

alt text

A: 

Is the containing cell being released?

If not, are you ever removing the UIActivityIndicatorView instance from the containing cell?

bbum
The documentation says that a UITableViewCell's contentView is responsible for releasing all views within it when the cell is removed. I don't think the developer is responsible for maintaining the memory unless it is specifically retained.
Shaun Budhram
Yes -- but if the developer is over-retaining the object or if the view hierarchy is not torn down correctly, then you'll end up with a leak.
bbum
A: 

I've come to the conclusion that this is due to the simulator - I do not receive these leaks on the actual device.

Shaun Budhram