Re: [newbie] NSString code so it won't leak, again
Re: [newbie] NSString code so it won't leak, again
- Subject: Re: [newbie] NSString code so it won't leak, again
- From: Jeff LaMarche <email@hidden>
- Date: Tue, 10 Sep 2002 08:33:34 -0700 (PDT)
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...
_______________________________________________
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.