• 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: Dean Davis <email@hidden>
  • Date: Tue, 10 Sep 2002 20:44:00 -0700 (PDT)

--- Ondra Cada <email@hidden> wrote:
>
> On Tuesday, September 10, 2002, at 03:58 , Dean
> Davis wrote:
>
> > NSString *string1,*myString
> >
> > string1 = [myString stringToIndex:41];
> > myString = [myString stringFromIndex:41];
> >
> > This works but leaks.
>
> It not only works; also, it does not leak. Read
> memory management, focus
> on autoreleasing.
>

I wrote a small test app that uses NSURLHandle to
download yahoo.com then sent the resource data to a
method. I extract the NSData to an NSString.
I do some code very similar to...
string1 = [myString stringToIndex:41];
myString = [myString stringFromIndex:41];

As far as I can tell with ObjectAlloc (thanks for the
tip) it leaks.

> > myString = [myString2 stringFromString:myString2];
> > // or? myString = [myString2 copy];
> > [myString2 release];
>
> This would crash, on the other hand.
> ---
> Ondra Cada
> OCSoftware: email@hidden
> http://www.ocs.cz
> private email@hidden
> http://www.ocs.cz/oc
>
Replaced the my first leaky example with the above
code. Not only does it not crash the application it
seems to stop the leak.

I posted my test project here...
http://www.afterten.com/Downloads/LeakTest.sit
For someone to verify or tell me what I'm doing wrong.
Cocoa is nice but fustrating that doesn't seem to be
any real authority on what needs to be released and
when. But I am reading all the links everyone has
posted on this thread.

Thanks.
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:
    • real authority on what needs to be released
      • From: James DiPalma <email@hidden>
    • Re: [newbie] NSString code so it won't leak
      • From: Andreas Mayer <email@hidden>
    • Re: [newbie] NSString code so it won't leak
      • From: Charles Srstka <email@hidden>
    • Re: [newbie] NSString code so it won't leak
      • From: Paul Nelson <email@hidden>
References: 
 >Re: [newbie] NSString code so it won't leak (From: Ondra Cada <email@hidden>)

  • Prev by Date: NSConnection registered names
  • Next by Date: Re: [newbie] NSString code so it won't leak
  • Previous by thread: Re: [newbie] NSString code so it won't leak
  • Next by thread: Re: [newbie] NSString code so it won't leak
  • Index(es):
    • Date
    • Thread