Why did instruments report a leak while its ref count did become zero
green hand i am. I'm using instruments, and it did a great help to me so far, but I'm confused now 'cause it report a memory leak to me while its leaked block history shows me that the ref count of that memory had finally become 0. What does it mean?
It's really embarrassing that I couldn't post a image here... so I have to describe it in text. Hope it would be clear enough for you:Event Type || RefCt || Responsible Library || Responsible Caller
Malloc || 1 || MyWeather || +[ForecastData parseSingleForecastWithXMLElement:] Autorelease|| || MyWeather || +[ForecastData parseSingleForecastWithXMLElement:] Retain || 2 || MyWeather || +[ForecastData parseWithData:] Release || 1 || Foundation || +[NSAutor开发者_StackOverflow社区eleasePool drain:] Retain || 2 || Foundation || +[NSThread initWithTarget:selector:object:] Release || 1 || Foundation || +[NSString compare:options:] Release || 0 || MyWeather || +[RootViewController dealloc]Any help will be appreciated~
It was caused by the lack of [super dealloc] in dealloc of forecastData, so that part of memory of forecastData is never freed while the retain count of forecastData did have become zero. Anyway, thanks guys.
you're not providing much sample code so it could be anything. The RefCount of MyWeather is zero but Foundation is still one, so maybe you have anywhere allocated a NSSting an never released?
btw. I would never alloc-init a string, instead setting the text directly and let the memory management do the rest. I don't know why but I think it's a little buggy. Sometimes I get strange errors if I try something like that:
NSString *str = [[NSString alloc] initWithString:@"some Text"];
myLabel.text = str;
[str release];
myLabel
should retain it but it doesn't. I will get an error if I try to release
it. (and a leak if not)
If I use
NSString *str = @"some Text";
myLabel.text = str;
it works great, no error and no leak.
Did you try this on the device? Sometimes you can see leaks show up that are not really leaks.
The other reason could have been that you had NSZombie enabled, which means objects don't really get released.
精彩评论