Re: Another strange thing, this time on retainCount
Re: Another strange thing, this time on retainCount
- Subject: Re: Another strange thing, this time on retainCount
- From: Greg Betzel <email@hidden>
- Date: Fri, 25 May 2001 22:05:55 -0500
On Friday, May 25, 2001, at 11:38 am, Stiphane Sudre wrote:
From what I'm seeing (from a lot of NSLog), [NSView
removeFromSuperview] doesn't decrease (instantly ?) the retainCount of
the NSView.
It's because -removeFromSuperview autoreleases the view (I'm not sure if
this is documented). Autorelease is cool, if sometimes confusing. :)
NSLog([[NSNumber numberWithInt:[currentTabView_ retainCount]]
stringValue]);
[[IBwindow_ contentView] addSubview:currentTabView_];
NSLog([[NSNumber numberWithInt:[currentTabView_ retainCount]]
stringValue]);
[currentTabView_ setFrameOrigin:tOrigin];
[currentTabView_ release];
The application crashes.
I'll bet the app is living after [currentTabView_ release], but dies
soon afterwards when the previous autorelease takes effect soon
afterwards.
For problems like this, take a look at NSDebug.h in Foundation. There's
all sorts of neat stuff, including enabling "zombies" (objects that
warn you when you try to access them after dealloc).
Hope this helps.
Greg Betzel