Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

XcodeNewb

macrumors member
Original poster
Feb 6, 2009
79
0
I am trying to release an object but the retain count doesn't change after the release:

Code:
	NSLog(@"removeTableViewScreen object retainCount1 [%d]", [myObject retainCount]);
	[myObject release];
	NSLog(@"removeTableViewScreen object retainCount2 [%d]", [myObject retainCount]);


The output to the console is as follows:

Code:
3/3/09 5:23:07 PM  removeTableViewScreen myObject retainCount1 [1] 
3/3/09 5:23:07 PM  removeTableViewScreen myObject retainCount2 [1]

Why wouldn't the release lower the retain count to 0??

myObject is a NSMutableArray with other objects added to it using the addObject method.

Thanks
 

tsornin

macrumors newbie
Jul 23, 2002
26
0
I don't think I'd worry about it too much. Per the docco on retainCount:

"This method is typically of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method."
 

Duke Leto

macrumors regular
Mar 17, 2008
166
0
Yeah I read the same quote from the docs when I had a crash .. I blamed it on a retainCount of 9 on an object!

Then of course I read the docs... and now the problem is solved!
 

mpatric

macrumors newbie
Oct 20, 2008
21
0
You're accessing the object after you've released it. I'm suprised the second line prints out at all.

What you might want to do if you really want to know about when your objects are being dealloc'd is overide the release method in each of your classes that you're interested in tracking, and get it to print out [self retainCount] - 1 before calling [super release].

DO MAKE SURE YOU CALL [super release] or things are going to go badly wrong.
 

mpatric

macrumors newbie
Oct 20, 2008
21
0
You mean [super dealloc], right? ;)

Nope, [super release]. I suggested to the originator of the thread that he override the release method to log the retain count before forwarding it on to the superclass.

Overriding release is something most people will never do.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.