• 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, again
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

More like...
-(void)myMethod:(NSData *)myData
{
NSString *myString,*myString2,string1;
myString = [NSString stringWithCString:[myData
bytes] length:[myData length]];

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

Using "TOP" (remember newbie, I don't know of a better
way to monitor memory usage) and running this method
over and over (once every five seconds) shows slow
increases on all the memory usages. If I do...
myString2 = [myString stringToIndex:41];
[myString release];
myString = [NSString stringWithString:myString2];
[myString2 release];

I do not see this memory creep with top.

I'm at work (on a peecee) and this was last night.
I'll recomfirm tonight when I get back on my Mac.

Dean Davis

--- Jeff LaMarche <email@hidden> wrote:
>
> On Tuesday, Sep 10, 2002, at 08:21AM, Dean Davis
> <email@hidden> wrote:
>
> >Actually, I'm downloading HTML using an
> NSURLHandle.
> >I'm passing the resourceData (an NSData) to a
> method
> >that converts the NSData to an NSString (hence
> >myString) and parses some data out of the HTML.
> >
> >I do the parsing in chunks so I so a search for a
> tag
> >and then break myString into two chunks based on
> the
> >index that the search returns. Chunk 1 goes to
> >"string1" with the balance replacing the contents
> of
> >"myString"
>
> So is your situation more like:
>
> -(void)myMethod:(NSString *)myString
> {
> NSString *newString = [myString stringToIndex:41];
> myString = [myString stringToIndex:41];
> }
>
> ?? In which case, you're still not leaking... you
> didn't allocate or retain myString, so you'd better
> not release it. Pointing it to a different value is
> not going to change its retain count.
>
> If you did alloc/init then you're going to need to
> release the old one and either alloc/init the new
> one, but in most cases this will be done using
> accessors since it's more likely to be your iVars
> where they'll be persisting beyond a single
method...


__________________________________________________
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: Jens Baumeister <email@hidden>
References: 
 >Re: [newbie] NSString code so it won't leak, again (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: NSMatrix for column of NSviews?
  • Next by Date: Re: Internet Explorer and Flash integration
  • Previous by thread: Re: [newbie] NSString code so it won't leak, again
  • Next by thread: Re: [newbie] NSString code so it won't leak, again
  • Index(es):
    • Date
    • Thread