• 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: Inconsistent Memory Management Rules
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistent Memory Management Rules


  • Subject: Re: Inconsistent Memory Management Rules
  • From: Sherm Pendley <email@hidden>
  • Date: Wed, 16 Apr 2003 02:10:50 -0400

On Tuesday, April 15, 2003, at 10:30 PM, Denis Stanton wrote:

Really? That simple? No alloc or retain = no leak?

I wouldn't go quite *that* far... No +alloc, -copy, +new, or -retain means that you're not responsible for releasing (or autoreleasing) the object.

A leak is still quite possible - if, for example, the code that *is* responsible for the object fails to release it properly.

I assumed that since I was using something called myDateString it must exist and therefore must be implicitly allocated space and therefore was a potential memory leak. As you saying that in my little example myDateString would just vanish when the method completed?

No, the methods you use to obtain myDateString - -objectAtIndex: and -stringByAppendingString: are not one of the three methods that return a retained object. In each case, the object you get back has either been autoreleased for you, or is retained by a collection object that has assumed responsibility for releasing it.

An autoreleased object does not vanish when the method completes. Its retain count is decremented when the active NSAutorelease pool is released. In a standard Cocoa app, a new pool is created at the start of each event, and released when all processing is finished for that event.

Further, an object that is released - either immediately with -release, or delayed with -autorelease - does not "vanish" immediately. Its retain count is decremented; only when the retain count reaches zero is the object de-allocated.

sherm--

"But i don't want to go among mad people," Alice remarked.
"Oh, you can't help that," said the Cat: "we're all mad here. I'm mad, You're mad."
"How do you know I'm mad?" said Alice.
"You must be," said the Cat, "or you wouldn't have come here."
"Alice in Wonderland" - Lewis Carrol
_______________________________________________
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: Inconsistent Memory Management Rules
      • From: Denis Stanton <email@hidden>
References: 
 >Re: Inconsistent Memory Management Rules (From: Denis Stanton <email@hidden>)

  • Prev by Date: Re: Inconsistent Memory Management Rules
  • Next by Date: Show Custom View Control
  • Previous by thread: Re: Inconsistent Memory Management Rules
  • Next by thread: Re: Inconsistent Memory Management Rules
  • Index(es):
    • Date
    • Thread