• 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: Filip van der Meeren <email@hidden>
  • Date: Fri, 21 Nov 2008 16:56:28 +0100

Ok, lets say that [NSString string] creates a new object each and every time a framework/Application needs an empty string (like about a billion times). Then the RAM would be stuffed with empty string objects that are useless for everyone.
Now they have created a fix for this, one size fits all. They did this in a special way, by fixing there retainCount in a special subclass of NSString:


retainCount
Returns the receiver’s reference count.

- (NSUInteger)retainCount

Return Value
The receiver’s reference count.

Discussion
You rarely send a retainCount message; however, you might implement this method in a class to implement your own reference-counting scheme. For objects that never get released (that is, their release method does nothing), this method should returnUINT_MAX, as defined in <limits.h>.


The retainCount method does not account for any pending autorelease messages sent to the receiver.

This method is typically of limited value in debugging memory management issues.


I quote: "For objects that never get released, this method should return UINT_MAX". So where do you see your bug ?



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

On 21 Nov 2008, at 16:44, mmalcolm crawford wrote:


On Nov 21, 2008, at 7:33 AM, Filip van der Meeren 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...

I do, and I already filed a bug.

Cocoa Fundamentals Guide states:

Class Factory Methods

"Class factory methods are implemented by a class as a convenience for clients. They combine allocation and initialization in one step and return the created object autoreleased. These methods are of the form + (type)className... (where className excludes any prefix)."
<http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_6.html >


It should probably not explicitly state "autoreleased" — it should simply state that — in accordance with standard memory management rules, in a reference counted environment — the receiver does not own the returned object.


mmalc


_______________________________________________

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: Jean-Daniel Dupas <email@hidden>
    • Re: Autorelease Question
      • From: Devon Ferns <email@hidden>
    • Re: Autorelease Question
      • From: mmalcolm crawford <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>)
 >Re: Autorelease Question (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: BOOL value in Dictionary
  • Next by Date: Re: NSIndexSet
  • Previous by thread: Re: Autorelease Question
  • Next by thread: Re: Autorelease Question
  • Index(es):
    • Date
    • Thread