• 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: why there is a memory leak in this method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Re: why there is a memory leak in this method?
      • From: "Philip Q" <email@hidden>
  • Prev by Date: Re: How do I give a set of methods to some objects but not others?
  • Next by Date: Re: Custom window resizer: flicker
  • Previous by thread: Re: why there is a memory leak in this method?
  • Next by thread: Re: Re: why there is a memory leak in this method?
  • Index(es):
    • Date
    • Thread