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

[newbie] NSString code so it won't leak, again


  • Subject: [newbie] NSString code so it won't leak, again
  • From: Dean Davis <email@hidden>
  • Date: Tue, 10 Sep 2002 07:00:36 -0700 (PDT)

Sorry, the first posting got screwed by Yahoo.

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.

  • Follow-Ups:
    • Re: [newbie] NSString code so it won't leak, again
      • From: "Clark S. Cox III" <email@hidden>
  • Prev by Date: [newbie] NSString code so it won't leak
  • Next by Date: iCal is available!
  • Previous by thread: Re: [newbie] NSString code so it won't leak
  • Next by thread: Re: [newbie] NSString code so it won't leak, again
  • Index(es):
    • Date
    • Thread