Re: NSWindowController retain count confusion
Re: NSWindowController retain count confusion
- Subject: Re: NSWindowController retain count confusion
- From: Jonathan Hess <email@hidden>
- Date: Tue, 30 Sep 2008 18:06:29 -0700
On Sep 30, 2008, at 12:01 PM, James Walker wrote:
Jonathan Hess wrote:
The method -[NSObject retainCount] only exists to aid in debugging.
You shouldn't be making any runtime decisions based on the return
value of retainCount. You should only release something you
previously retained/alloced/newed/copied or are for some other
reason explicitly required to release. If you think you have a
leak, you might consider running your app with Instruments's Object
Alloc and Leaks tools. With those tools, you'll be able to get a
backtrace for reach release, retain, and autorelease message sent
to the instance of window you're curious about.
If you were to add a double release, and it wasn't the case that
your class was responsible for a double retain, then as soon as the
unbalanced retain is found and fixed, your program will start
crashing.
I tried Instruments, and got nowhere with it. It showed hundreds of
retains and releases in Foundation and AppKit, and I had no way to
know what was significant.
However, I did solve my problem. I neglected to mention that I'm
working in a mostly Carbon app. When I surrounded the alloc, init,
and showWindow calls with a local autorelease pool, the problem went
away and the NSWindowController gets deallocated without funny
business. I thought I had read that it was no longer necessary to
set up my own autorelease pools.
Interesting. Was there a corresponding console message about an object
being autoreleased with no pool in place? If not, you should consider
filing a radar with a small reproducible test case.
It's good to hear you resolved your issue -
Jon Hess
On Sep 29, 2008, at 7:30 PM, James Walker wrote:
I have an NSWindowController subclass that is defined as File's
Owner in a nib. The window outlet is connected to a window, and
the delegate outlet of the window goes back to the File's Owner. I
was trying to release the controller in the windowWillClose:
delegate method, but it didn't cause the dealloc method to be
called. I found that immediately after creating the controller
with alloc and init, its retain count was 1, but as soon as I did
[self window], the retain count went up to 2. So, who's retaining
the controller, and is it safe to just release it twice?
I searched the list, and found some old messages about
NSWindowController retain counts being messed up by bindings, but
I don't have any bindings (yet).
--
James W. Walker, Innoventive Software LLC
<http://www.frameforge3d.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden