A question of memory management style
A question of memory management style
- Subject: A question of memory management style
- From: John Brownie <email@hidden>
- Date: Mon, 18 Jul 2011 07:32:50 +0300
I'm a relative newcomer to Cocoa, and I'm rewriting my Carbon-based
application in Cocoa, taking the opportunity to refactor and improve the
structure of my code.
One area is giving me some difficulty in working out what is
appropriate. The basic idea is to split off the handling of a particular
event, such as dropping text on a view, and encapsulating all the logic
and interactions (dialogs where necessary) associated with that as a
separate class. This is working fine, but the static analyzer of Xcode
3.2.6 doesn't like my memory management practice with this.
In the document object, I am observing such an event, then creating a
handler and calling it. I have handled creation either by explicit
allocation such as [[HandlerClass alloc] initWith...] or by writing a
class method to create an object like [HandlerClass
createHandlerWith...]. I then call the appropriate action method like
[handlerObject beginProcesssing...] and return to the event loop. The
handler class handles interactions, and releases itself when it is done.
This does not result in leaks, but the analyzer warns me that the
handler is potentially leaking from the document class.
So my question is, what model of memory management is appropriate?
Should I stick with what I have, where the document object creates the
handler and then forgets it, knowing that the handler will clean up
after itself when it's done? Or should I have the handler retain itself,
and have the document object release it? Or is there another method I
haven't thought of?
Thanks for any suggestions!
John
--
John Brownie, email@hidden or email@hidden
Summer Institute of Linguistics | Mussau-Emira language, Mussau Is.
Ukarumpa, Eastern Highlands Province | New Ireland Province
Papua New Guinea | Papua New Guinea
_______________________________________________
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