Re: why there is a memory leak in this method?
Re: why there is a memory leak in this method?
- Subject: Re: why there is a memory leak in this method?
- From: Matt Neuburg <email@hidden>
- Date: Fri, 24 Nov 2006 08:24:01 -0800
- Thread-topic: why there is a memory leak in this method?
On Fri, 24 Nov 2006 14:21:46 +0800, Leo <email@hidden> said:
>NSAttributedString *test=[[[NSAttributedString alloc]
>initWithHTML:[tmpTag dataUsingEncoding:[tmpTag fastestEncoding]]
>documentAttributes:nil] autorelease];
>hTag=[test string];
>
>}
>
>return hTag;
>
>}
>
>when i test it with MallocDebug and it displays there is a memory leak
>in [NSAttributedString alloc] initWithHTML, but i have already
>autorealease it, why it still has a leak? should i use NSAutoreleasePool?
You never know for sure what autorelease will return, so my first piece of
advice would be to write it like this:
NSAttributedString *test=
[[NSAttributedString alloc] initWithHTML:
[tmpTag dataUsingEncoding:[tmpTag fastestEncoding]]
documentAttributes:nil];
[test autorelease];
Second, are you planning to modify the NSAttributedString's string directly?
If not - that is, if you just want to see it - consider making a copy. In
that case you can just release the original attributed string.
NSAttributedString *test =
[[NSAttributedString alloc] initWithHTML:
[tmpTag dataUsingEncoding:[tmpTag fastestEncoding]]
documentAttributes:nil];
hTag = [[test string] copy];
[test release];
[hTag autorelease];
See if any of that helps. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins (at) lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden