• 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: [newbie] NSString code so it won't leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] NSString code so it won't leak


  • Subject: Re: [newbie] NSString code so it won't leak
  • From: Andreas Mayer <email@hidden>
  • Date: Wed, 11 Sep 2002 12:43:53 +0200

Am Mittwoch, 11.09.02 um 05:44 Uhr schrieb Dean Davis:

string1 = [myString stringToIndex:41];
myString = [myString stringFromIndex:41];

Well, *I* think this may very well leak. At least if myString was not autoreleased in the first place.

If, on the other hand, myString was a constant string (myString = @"whatever") or it has been autoreleased before, then this code should *not* leak.

The problem is that, in the second line, the reference to the original myString object is lost.

[myString autorelease];
string1 = [myString stringToIndex:41];
myString = [myString stringFromIndex:41];

or

oldMyString = myString;
string1 = [myString stringToIndex:41];
myString = [myString stringFromIndex:41];
[oldMyString release];

should work in this case.

Or did I miss something here?


bye. Andreas.
_______________________________________________
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.

References: 
 >Re: [newbie] NSString code so it won't leak (From: Dean Davis <email@hidden>)

  • Prev by Date: IOKit: getting optical drive type
  • Next by Date: Newbie question
  • Previous by thread: Re: [newbie] NSString code so it won't leak
  • Next by thread: real authority on what needs to be released
  • Index(es):
    • Date
    • Thread