【发布时间】:2011-03-10 18:00:15
【问题描述】:
我在发布和泄漏方面遇到了真正的麻烦。我有一个不会停止泄漏的数组!这是我的代码: 我在 .h 中声明了 otherValuesArray 我尝试了数百种不同的方法,包括自动释放。
谁能告诉我我做错了什么?谢谢
otherValuesArray = [[NSMutableArray array] retain]; //89% leak
NSString *tempString;
tempString = [[NSString stringWithFormat:@"%d",challengeID] autorelease];
[otherValuesArray addObject:[NSString stringWithString:tempString]]; // 11% leak
tempString=nil;
tempString = [[NSString stringWithFormat:@"%d",scoreMultiQuant] autorelease];
[otherValuesArray addObject:[NSString stringWithString:tempString]];
tempString=nil;
int challengeDoneTemp = [challenges otherValues:otherValuesArray];
tempString=nil;
[tempString release];
otherValuesArray = nil;
[otherValuesArray release];
【问题讨论】:
-
顺便说一句,我在其他
[otherValuesArray addObject:[NSString stringWithString:tempString]];行上遇到了泄漏,直到我添加了:tempString=nil;。我也尝试更改为otherValuesArray = [[NSMutableArray array] autorelease];和otherValuesArray = [NSMutableArray array];但它崩溃了 -
Xcode 没有泄漏,它只是您用来编写代码的 IDE。
标签: objective-c cocoa-touch memory nsmutablearray memory-leaks