On Fri, Jul 18, 2008 at 7:42 AM, Shawn Erickson <[EMAIL PROTECTED]> wrote:
> On Fri, Jul 18, 2008 at 7:34 AM, Matthias Arndt
> <[EMAIL PROTECTED]> wrote:
>> Robert,
>>
>> Am 18.07.2008 um 16:25 schrieb Robert Martin:
>>
>>> In the next line, you reassign vAttributes to the contents of your iVar
>>> dictionary. Nothing points to that alloc'd dictionary in the first line
>>> anymore.
>>>
>>> Since vAttributes now points to an autoreleased dictionary, attempting to
>>> release it will cause a crash.
>>
>> THAT makes sense, I just didn't realize that "objectForKey" returns an
>> autorelease object! I just removed the first allocation of "vAttributes"
>> what fixes the problem.
>
> This is the wrong thing to take away from this email thread. Please
> review the following and ask questions if you don't understand any
> aspect of it.
>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html>
>
> ...and review the whole of the document that contains the above...
>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html>

I should more clearly note that objectForKey: is not returning an
"autoreleased" object. Also even if it did it would be an
implementation detail (unless documented in the API docs).

It is returning a reference to an object that the vColors dictionary
has a retained reference to (Cocoa collections retain what you add to
them). At this point in time you have know idea of the lifetime of the
object you get back (it could go away when the vColors dictionary goes
away or it could live longer). If you need something to stay around
outside of the method you are in (assuming no side effects down stream
in that method) then you must retain that object for a long as you
need it.

-Shawn
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to