• 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
Re: A question of memory management style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question of memory management style


  • Subject: Re: A question of memory management style
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 17 Jul 2011 22:01:32 -0700

On Jul 17, 2011, at 9:32 PM, John Brownie wrote:

> 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?

The way you’re doing it is reasonable, but the analyzer isn’t smart enough to tell. If you want to avoid the warnings (which seems like a good idea; it’s never good to leave false warnings around) you could change the code so the handler’s beginProcessing method retains itself, and the handler releases itself when it’s done. Then the code that creates a handler can release it, and all the memory management looks kosher to the analyzer. (This is the way other asynchronous classes like NSURLConnection work.)

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >A question of memory management style (From: John Brownie <email@hidden>)

  • Prev by Date: Re: NSTextView won't deallocate
  • Next by Date: Re: A question of memory management style
  • Previous by thread: A question of memory management style
  • Next by thread: Re: A question of memory management style
  • Index(es):
    • Date
    • Thread