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

Re: More memory management questions


  • Subject: Re: More memory management questions
  • From: Sherm Pendley <email@hidden>
  • Date: Sat, 2 Mar 2002 01:29:48 -0500

On Friday, March 1, 2002, at 08:37 PM, David Newberry wrote:

My question here is, if I do something like this:
NSString *string = [NSMutableString stringWithString:@"temp"];
Have I "allocated" this object?

No. "Allocate, copy, or retain" means calling "alloc," "copy," or "retain" methods. These methods must be "balanced" by a corresponding "release" or "autorelease" when the object is to be disposed of.

If not, should it be treated as a received object (below)?

Yes.

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?

Yes.

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

It will take up memory until it's either released or autoreleased.

sherm--
_______________________________________________
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.

References: 
 >More memory management questions (From: David Newberry <email@hidden>)

  • Prev by Date: Re: Cocoa, Java vs. Objective-C
  • Next by Date: Re: Multiple windows in a doc based app How-To
  • Previous by thread: More memory management questions
  • Next by thread: Re: More memory management questions
  • Index(es):
    • Date
    • Thread