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

why there is a memory leak in this method?


  • Subject: why there is a memory leak in this method?
  • From: Leo <email@hidden>
  • Date: Fri, 24 Nov 2006 14:21:46 +0800

Hi all:

I have a simple method:

- (NSString *)hTagString:(NSString *)source{
NSString *hTag=nil;

NSRange startRange=[source rangeOfString:@"<h1"
options:NSCaseInsensitiveSearch];

if(startRange.length!=0){
NSRange endRange=[source rangeOfString:@"</h1>"
options:NSCaseInsensitiveSearch];
NSRange tmpRange=[source rangeOfString:@">" options:NSCaseInsensitiveSearch
range:NSMakeRange(startRange.location+startRange.length,endRange.location-startRange.location-startRange.length)];

int start=tmpRange.location+tmpRange.length;

int len=endRange.location-tmpRange.location-tmpRange.length;

NSString *tmpTag=[source substringWithRange:NSMakeRange(start,len)];


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?

Does anybody can help me, thank you.


Leo


_______________________________________________

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: why there is a memory leak in this method?
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: Diggest [:.VIRUS.:]
  • Next by Date: Re: ObjectAlloc tool and framework debugging
  • Previous by thread: Re: User list [:.VIRUS.:]
  • Next by thread: Re: why there is a memory leak in this method?
  • Index(es):
    • Date
    • Thread