Re: [Q] Weird problem with the NSTableView
Re: [Q] Weird problem with the NSTableView
- Subject: Re: [Q] Weird problem with the NSTableView
- From: Ryan Britton <email@hidden>
- Date: Wed, 6 Dec 2006 20:53:03 -0800
When you use a convience method such as +arrayWithObjects:, you do
not "own" the object and the memory management pattern used by it and
all other AppKit and Foundation methods of the same type is to
autorelease the resulting object. That is, it will disappear the
next time the autorelease pool is drained (generally the next
iteration of the run loop unless you're doing some custom management).
To stake a claim to that object and essentially indicate to the
runtime that you want it to stick around until you're done with it,
you must retain it. When you're done with it for good, you can then
release it. Once the last claim is released, it will be freed.
On Dec 6, 2006, at 8:39 PM, JongAm Park wrote:
Um.. For the 1), well.. it was typo. I'm sorry. When I wrote email,
I didn't comment it out. I'm sorry.
2).. Well, this was the reason. However it was created with the
convenience method, arrayWithObject, not initWithObject. So, the it
should be handled automatically. it is also said in the document.
-- Creating Objects Using Convenience Methods --
Many classes provide methods of the form +className... that you can
use to obtain a new instance of the class. Often referred to as
“convenience constructors”, these methods create a new instance of
the class, initialize it, and return it for you to use. Although
you might think you are responsible for releasing objects created
in this manner, that is not the case according to the policy Cocoa
set—the method name does not contain "alloc" or "copy", or begin
with "new". Because the class creates the new object, it is
responsible for disposing of the new object. A
----------------------------------------------------------------------
------------------
However, when I append 'retain" to to arrayWithObjects, the problem
is gone. It is strange to me.
Do I misunderstand something?
Thanks.
Shawn Erickson wrote:
1) You appear to set the value of encodingStringArray_CF twice in
the above code.
2) You don't retain the array you assign to
encodingStringArray_CF. (review Cocoa memory management [1])
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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)
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