• 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
More memory management questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

More memory management questions


  • Subject: More memory management questions
  • From: David Newberry <email@hidden>
  • Date: Fri, 1 Mar 2002 17:37:34 -0800

Hello all,

Again I'd like to thank you all for the help on my previous questions. This is an extension of that, relating to memory management.

The summary of "Object Ownership and Disposal" says:
"* If you directly allocate, copy, or retain an object, you are responsible for releasing the newly created object with release or autorelease. Any other time you receive an object, you are not responsible for releasing it."

My question here is, if I do something like this:
NSString *string = [NSMutableString stringWithString:@"temp"];
Have I "allocated" this object? If not, should it be treated as a received object (below)?

"* A received object is normally guaranteed to remain valid within the method it was received in (exceptions include multithreaded applications and some Distributed Objects situations). That method may also safely return the object to its invoker."

This sounds like (as far as my understanding goes), you should treat received objects as though they were sent an autorelease message before being returned. Is this a reasonable assumption, at least for understanding the object's behavior?

"* If you need to store a received object in an instance variable, you must retain or copy it."

This also sounds to me like it was sent an autorelease message.

"* Use retain and autorelease when needed to prevent an object from being invalidated as a normal side-effect of a message."

My question here is: If you have an allocated object that hasn't received any retain or [auto]release messages, what will it do? Stick around forever? or be removed with the next NSAutoreleasePool call?

Lastly: I'm experimenting with getting my memory management right, and am (predictably -- I am a newbie to Cocoa) getting exceptions in the NSAutoreleasePool method. Is there any way for me to know what object it is that causes the exception?

Thanks again.

Peace,
-David Newberry
_______________________________________________
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: More memory management questions
      • From: Jonathan Jackel <email@hidden>
    • Re: More memory management questions
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: PackageMaker package resources question
  • Next by Date: Re: C++?
  • Previous by thread: PackageMaker package resources question
  • Next by thread: Re: More memory management questions
  • Index(es):
    • Date
    • Thread