Re: [newbie] NSString code so it won't leak
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.