• 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: Autorelease Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autorelease Question


  • Subject: Re: Autorelease Question
  • From: Adam Leonard <email@hidden>
  • Date: Fri, 21 Nov 2008 10:45:48 -0500

Ok, yeah, it could call autorelease, but that would amount to a noop.
My problem with this documentation is that if I created a class that had a method just like the one you mentioned:


+ (Foo*)foo
{
	static Foo *result = nil;
	if(!result)
	{
		// Go freaky...

		// Something like this
		result = [[Foo alloc] initWithBytes:nil];
		[result setThisRetainCountToMax];
	}

	return result;
}

This documentation would say this code is wrong for two reasons:
- It does not call autorelease
- Except for the first time it is called, it does not "combine allocation and initialization" (It just returns the singleton instance)


Now, I think this code is totally fine (though for an actual singleton, you would not set the retain count, but rather just override -retain, -release-, -autorelease, and -retainCount).

The rules of memory management suggest this code is fine too.

Therefore, I can only conclude that the generalization made by this page in the documentation (for beginners no less) is simply wrong.

Adam Leonard

On Nov 21, 2008, at 10:33AM, Filip van der Meeren wrote:


Filip van der Meeren http://www.sourceforge.net/projects/xlinterpreter

On 21 Nov 2008, at 16:21, Adam Leonard wrote:

Ok, so my point with all this is that the documentation should not say that all class factory methods always return autoreleased objects because that is an implementation detail that (a) is not required by the memory management rules, (b) is something that the programmer should not care about, and (c) is not even true in the case of some methods, including [NSString string]

So I'll file a bug.


You will file a bug ? I really do not see the bug here...

And for the very last time in this discussion... Where do you people get the fact that [NSString string] doesn't call autorelease ?
It might call it, and just have its retaincount fixed to a certain number...


Adam Leonard

On Nov 21, 2008, at 9:43AM, Kyle Sluder wrote:

On Thu, Nov 20, 2008 at 11:53 PM, Luke Hiesterman <email@hidden > wrote:
So thinking gets in the way of understanding and not thinking is the path to
enlightenment?

This is a bogus question. You're thinking incorrectly. There's a
reason the memory management rules don't explicitly call for things to
be autoreleased. Following good OO principles, you shouldn't care how
things are memory managed within the framework; just make sure you're
doing the right thing and following the rules, and everyone's a
winner.


--Kyle Sluder
_______________________________________________

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


_______________________________________________

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



_______________________________________________

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: Autorelease Question
      • From: Filip van der Meeren <email@hidden>
References: 
 >Autorelease Question (From: "Carmen Cerino Jr." <email@hidden>)
 >Re: Autorelease Question (From: Joseph Crawford <email@hidden>)
 >Re: Autorelease Question (From: Alexander Spohr <email@hidden>)
 >Re: Autorelease Question (From: Adam Leonard <email@hidden>)
 >Re: Autorelease Question (From: Klaus Backert <email@hidden>)
 >Re: Autorelease Question (From: Adam Leonard <email@hidden>)
 >Re: Autorelease Question (From: Kiel Gillard <email@hidden>)
 >Re: Autorelease Question (From: Jim Correia <email@hidden>)
 >Re: Autorelease Question (From: Luke Hiesterman <email@hidden>)
 >Re: Autorelease Question (From: "Kyle Sluder" <email@hidden>)
 >Re: Autorelease Question (From: Adam Leonard <email@hidden>)
 >Re: Autorelease Question (From: Filip van der Meeren <email@hidden>)

  • Prev by Date: Re: Autorelease Question
  • Next by Date: Apple-like chat bubbles
  • Previous by thread: Re: Autorelease Question
  • Next by thread: Re: Autorelease Question
  • Index(es):
    • Date
    • Thread