• 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: Notifications and memory management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notifications and memory management


  • Subject: Re: Notifications and memory management
  • From: Greg Titus <email@hidden>
  • Date: Sat, 30 Mar 2002 15:16:57 -0800

On Saturday, March 30, 2002, at 10:45 AM, Jay Kuri wrote:
Basically what I'm trying to determine is:
1) do I need to retain the object from the userInfo dictionary if I want to keep it?

Yes.

2) if I don't retain it, how long can I expect to have a valid object?

Until the notification is released, which releases the user info dictionary, which releases that object. (See below.)

3) When do Notifications get released? Is it automatic?

Like everything else, if you didn't call +retain, +copy, or +alloc on it, the object is already autoreleased. So the notification will get released whenever the autorelease pool that contains it gets cleaned up.

If you don't have your own autorelease pool, that will be at the end of the current event loop, since Cocoa has an automatic autorelease pool around each event handled.

Thanks for any help or pointers!

Basically, there isn't anything special about NSNotification objects - they follow the same rules as everything else. Getting comfortable with -retain, -release, -autorelease will help a lot. (There's some good tutorials out there on this topic - check the one on www.stepwise.com, for instance.)

Hope this helps,
--Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Notifications and memory management
      • From: Jay Kuri <email@hidden>
References: 
 >Notifications and memory management (From: Jay Kuri <email@hidden>)

  • Prev by Date: Re: Make a NSString with an integer
  • Next by Date: Re: Make a NSString with an integer
  • Previous by thread: Notifications and memory management
  • Next by thread: Re: Notifications and memory management
  • Index(es):
    • Date
    • Thread