• 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: String memory leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String memory leak


  • Subject: Re: String memory leak
  • From: Ondra Cada <email@hidden>
  • Date: Mon, 3 Apr 2006 08:51:46 +0200

Paul,

On 3.4.2006, at 2:26, Paul Forgey wrote:

I'm not certain why the accessor is retaining it and then adding that count to the autorelease pool.

Because that's the proper accessor pattern. Plain accessors are dangerous; they should be used only in cases the efficiency makes it necessary, and should be explicitly documented as such -- a good example are primitive containers.


If the caller wants an instance of the glass string beyond the lifetime of the class instance owning it or it being changed, it should retain it itself.

Wrong. With plain accessors you are advocating:

So why not:

- (NSString *)glass {
    return glass;
}

the caller would have to retain *all the time*, since you never can know where a change may occur:


NSString *currentGlass=[object glass];
// any non-trivial code here
NSLog(@"%@",currentGlass);

With plain accessors this code is prone to crash as soon as the "non- trivial code" happens to change the object's glass. Since Obj-C is a dynamic language, you can never know whether it does: it may not now, it may in future -- e.g., loading a plug-in with a category or a poseAsClass.

You may advocate that in such a case it is the new code responsibility not to change the glass, but that would not make sense: then *no* new code could *ever* use any setter.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: String memory leak (From: Bruce Truax <email@hidden>)
 >Re: String memory leak (From: Paul Forgey <email@hidden>)

  • Prev by Date: get window server?
  • Next by Date: Re: get window server?
  • Previous by thread: Re: String memory leak
  • Next by thread: Re: cocoa app using external c++ code
  • Index(es):
    • Date
    • Thread