Re: primitiveValueForKey Memory Management
Re: primitiveValueForKey Memory Management
- Subject: Re: primitiveValueForKey Memory Management
- From: email@hidden
- Date: Sun, 29 May 2005 23:22:12 +1000
I'm worried that this will result in a memory leak though.
It will, unless you explicitly take pains to release 'name' later.
What is the proper way to do this?
I'm not familiar with CoreData, but in terms of general ObjC memory
management, you should technically be returning [[tmpValue retain]
autorelease] (which is also what primitiveValueForKey should be
returning anyway). If this doesn't work, I'd consider laying the
blame on NSOutlineView, which would then be the only source of error
I could see, and which is responsible for retaining "name"
appropriately.
It seems unlikely your current method would fail anyway if
NSOutlineView were retaining things properly... so I'm guessing
NSOutlineView is either buggy, or specifies this behaviour as
"caveat" in it's documentation; I'm not familiar with it so I don't
know either way.
The thought does occur though that willAccessValueForKey: may alloc
memory, and didAccessValueForKey: will release it... I doubt it, but
just in case, you should probably do a [tmpValue retain] before you
call didAccessValueForKey:, and then return [tmpValue autorelease].
Again though, this would indicate a design flaw in CoreData (or
whatever these primitive key methods are), in my mind - it should be
returning an autoreleased value, to avoid any such concerns in a
procedural method.
Wade Tregaskis (AIM/iChat, Yahoo & Skype: wadetregaskis, ICQ:
40056898, MSN, audio/video iChat & email: email@hidden,
Jabber: email@hidden)
-- Sed quis custodiet ipsos custodes?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden