• 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: In-loop releasing of objects does not free memory?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: In-loop releasing of objects does not free memory?


  • Subject: Re: In-loop releasing of objects does not free memory?
  • From: Jim Correia <email@hidden>
  • Date: Fri, 15 Feb 2008 08:41:29 -0500

On Feb 14, 2008, at 11:36 PM, j o a r wrote:

On Feb 14, 2008, at 7:57 PM, Jim Correia wrote:

But -release is a no-op in GC code. NSAutoreleasePool will never get the message. So we need a new message that we can send NSAutoreleasePool that it will actually get when running in GC mode. And for convenience, in non-GC mode it should do the same thing as -release always did, to provide a single, simple idiom for inner autorelease pools that will work in either GC or non-GC mode.

Yes, strictly speaking, it is inconsistent. But also necessary; the alternatives would be uglier.

I don't know if I agree. Rather than repeatedly creating and destroying a local autorelease pool in a non-GC app, why not instead using "-drain" with the same type of semantics as in GC?

Well, I was trying to provide a plausible explanation for why we ended up with -drain as a synonym for -release, not second guess the decision with the advantage of hindsight (and the disadvantage of not having all the facts before me.).


---------------------------------------------
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	for (id foo in foos)
	{
		// Stuff...
		[pool drain];
	}
	[pool release];
---------------------------------------------

Much better IMO. The above would work fine in both GC and non-GC, and it doesn't suffer from the completely unexpected behaviour of having (drain == release) in non-GC.

This doesn't suffer from the problem where -drain is now a special case and is equivalent to release in a non-GC app. (But as I mentioned, NSAutorelease pool was already a bit of a special case anyway.)


It has the disadvantage that it is a bigger change in the previous idiom for existing code which destroyed and created a new pool every loop iteration. (Or every N loop iterations.)

(And there certainly could have been additional issues we haven't considered.)

Now, this is all a moot point of course... :-)

Indeed. -drain is what it is, and is documented that way :-)

Jim

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: In-loop releasing of objects does not free memory?
      • From: glenn andreas <email@hidden>
References: 
 >In-loop releasing of objects does not free memory? (From: Arthur C. <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: John Terranova <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: John Stiles <email@hidden>)
 >RE: In-loop releasing of objects does not free memory? (From: Arthur C. <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Randall Meadows <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Uli Kusterer <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Nick Zitzmann <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Randall Meadows <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Michael Watson <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Keith Duncan <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: Jim Correia <email@hidden>)
 >Re: In-loop releasing of objects does not free memory? (From: j o a r <email@hidden>)

  • Prev by Date: Re: Set focus on NSView in an NSMenuItem
  • Next by Date: Re: NSShadow changes on 10.5.2?
  • Previous by thread: Re: In-loop releasing of objects does not free memory?
  • Next by thread: Re: In-loop releasing of objects does not free memory?
  • Index(es):
    • Date
    • Thread