我被Cocoa内存管理卡住了。
- (IBAction) createPush:(UIButton *)sender {
[create setEnabled:NO];
[release setEnabled:YES];
aLocation = [[Location alloc] init];
// Put some Example Stuff in the Class
aLocation.title = @"Apartment";
aLocation.street = @"Examplestreet 23";
aLocation.zip = @"12345";
aLocation.city = @"Exampletown";
aLocation.http = @"http://google.com";
aLocation.info = @"First Info Text";
aLocation.info2 = @"Second Info Text, not short as the first one";
aLocation.logoPath = @"http://google.de/nopic.jpg";
[aLocation.pictures addObject:@"http://google.de/nopic.jpg"];
[aLocation.pictures addObject:@"http://google.de/nopic.jpg"];
}
- (IBAction) releasePush:(UIButton *)sender {
[release setEnabled:NO];
[create setEnabled:YES];
[aLocation release];
aLocation = nil;
}如果我设置或获取变量,这段代码可以很好地工作,但当我调用‘最后’版本(因此保留计数为0)时,它会调用aLocation的dealloc方法,但在工具分配中,您会看到没有返回内存。
这里是位置的来源:
为头文件使用'.h‘而不是'.m’的http://homes.dnsalias.com/sof/Location.m相同链接(很抱歉,这是因为垃圾邮件规则)。
整个项目:http://homes.dnsalias.com/sof/Location.zip
谢谢你的帮助,我的失败在哪里?丹尼斯
发布于 2011-05-05 11:39:45
如果我设置或获取变量,这段代码工作得很好,但当我调用‘最后’版本(因此保留计数为0)时,它会调用aLocation的dealloc方法,但在工具分配中,您会看到没有返回内存。
你说的“没有记忆是不会还给的”是什么意思?
尽管名称奇怪,但上面的代码(假设您也在dealloc中发布了它)表明aLocation的内存管理是正确的。
为什么当单个对象被释放时,内存使用不会减少?
(转述)
您的对象可能相对较小,因此,单个释放低于在Instruments中显示所需的~20K左右。
如果你的应用程序因为内存使用问题而崩溃,那么从单一的释放开始是错误的。要做的第一件事是回答为什么你的应用程序会增加内存,以及是什么导致了这种增长。
将分配工具配置为仅跟踪实时分配。然后按总内存使用量排序。这将向您显示哪种类型的分配消耗最多的内存。从减少这一点开始。
在这些情况下,Heapshot analysis可能非常有效。
发布于 2011-05-05 17:19:30
额外的信息在这里,因为链接的最大数量,我没有机会张贴图片…
你说的“没有退还的内存”是什么意思?
我将向您展示Instruments运行,然后它应该是清晰的。Screenshots from Instruments run
如果需要更多详细信息,请单击here for Instruments Run。
发布于 2011-05-05 17:36:26
你的代码很好。你搞错了Instruments的输出。没有Location对象泄漏。
对于泄漏,请使用“泄漏”工具。它不能开火。:-)
https://stackoverflow.com/questions/5886911
复制相似问题