• 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: NSDictionary dictionaryWithContentsOfFile in Carbon app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary dictionaryWithContentsOfFile in Carbon app


  • Subject: Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
  • From: Uli Kusterer <email@hidden>
  • Date: Sun, 8 Oct 2006 12:53:20 +0200

Am 08.10.2006 um 09:52 schrieb Roni Music:
I have a Carbon application and I have just added my first Cocoa stuff and have a couple of questions relating to have memory is deallocated.
Everything seems to work fine but I'm curious if I'm doing things correctly (I'm a newbie with Obj-C and Cocoa).

In short, you're doing it wrong. Autorelease pools are not like Apache API memory pools. They're not intended to be kept around in instance vars (they stack, so you really should only create one at the start of a function and release it at the end).


Just create the pool at the start of any function that calls into Cocoa and release it before exiting the function. May be a good idea to create an auto_ptr-like object to take ownership of and release ObjC objects. Another good idea would be to add ObjC exception handlers, too, see NS_DURING and NS_HANDLER and NS_ENDHANDLER or @try and @catch -- C++ doesn't understand ObjC exceptions.

If you want to keep any object that you don't own (see <http:// devworld.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/ MemoryManagementRules.html> for details on ownership), you must retain it before you store it in an ivar and release it once you don't need it anymore (e.g. before replacing it with a new object when you change its value and in your destructor). If you already own it, you can just store it away in an ivar, but you still need to release it.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de


_______________________________________________ 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
  • Follow-Ups:
    • Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
      • From: "Roni Music" <email@hidden>
References: 
 >NSDictionary dictionaryWithContentsOfFile in Carbon app (From: Roni Music <email@hidden>)

  • Prev by Date: Re: editor framework
  • Next by Date: Modifying output of print operation
  • Previous by thread: NSDictionary dictionaryWithContentsOfFile in Carbon app
  • Next by thread: Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
  • Index(es):
    • Date
    • Thread