[newbie] NSString code so it won't leak
[newbie] NSString code so it won't leak
- Subject: [newbie] NSString code so it won't leak
- From: Dean Davis <email@hidden>
- Date: Tue, 10 Sep 2002 06:58:32 -0700 (PDT)
In languages I'm used to you could write code like...
myString = "SOME BIG LONG ... STRING"
string1 = left(myString,40)
myString = mid(myString,41)
Thereby isolating the first 40 characters to string1
and the balance going back into myString
In Cocoa I was using...
NSString *string1,*myString
string1 = [myString stringToIndex:41];
myString = [myString stringFromIndex:41];
This works but leaks.
So what's better?
All I've come up with is
string1 = [myString stringToIndex:41];
myString2 = [myString stringFromIndex:41];
[myString release];
myString = [myString2 stringFromString:myString2];
// or? myString = [myString2 copy];
[myString2 release];
Would simply making myString as a NSMutableString make
the first code section not leak?
Dean Davis
__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute
_______________________________________________
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.