• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
A question of memory management style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: A question of memory management style
      • From: Scott Ribe <email@hidden>
    • Re: A question of memory management style
      • From: vincent habchi <email@hidden>
    • Re: A question of memory management style
      • From: Jens Alfke <email@hidden>
  • Prev by Date: NSTextView won't deallocate
  • Next by Date: Re: NSTextView won't deallocate
  • Previous by thread: Re: NSTextView won't deallocate
  • Next by thread: Re: A question of memory management style
  • Index(es):
    • Date
    • Thread