2

我是新手。我正在使用工具,到目前为止它对我有很大帮助,但我现在很困惑,因为它向我报告了内存泄漏,而它泄露的块历史显示该内存的引用计数最终变为 0 。 这是什么意思?
在这里发不了图片真的很尴尬……所以我不得不用文字来描述它。希望对您来说足够清楚:

事件类型 || 参考 || 责任图书馆 || 负责任的来电者
Malloc || 1 || 我的天气 || +[ForecastData parseSingleForecastWithXMLElement:]
自动释放|| || 我的天气 || +[ForecastData parseSingleForecastWithXMLElement:]
保留 || 2 || 我的天气 || +[ForecastData parseWithData:]
发布 || 1 || 基金会 || +[NSAutoreleasePool 流失:]
保留 || 2 || 基金会 || +[NSThread initWithTarget:selector:object:]
释放 || 1 || 基金会 || +[NSString compare:options:]
发布 || 0 || 我的天气 || +[RootViewController 解除分配]

任何帮助将不胜感激~

4

3 回答 3

4

这是由于forecastData的dealloc中缺少[super dealloc]造成的,导致forecastData的部分内存从未被释放,而forecastData的retain count确实变为零。无论如何,谢谢各位。

于 2010-12-21T06:47:23.197 回答
0

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.

于 2010-12-18T19:14:30.800 回答
0

你在设备上试过吗?有时您会看到泄漏并不是真正的泄漏。

另一个原因可能是您启用了 NSZombie,这意味着对象并没有真正被释放。

于 2010-12-18T19:47:05.993 回答