我的最新应用程序处于内存泄漏清理模式,并且遇到了一些我无法解决的问题。
除了 1 个烦人的问题外,以下方法已被清理。Instruments 告诉我,我的名为 itemsToKeep 的 NSMutableArray 正在泄漏内存,此时我正在创建对象。任何关于我为什么泄漏内存的想法将不胜感激。
以下是关于 retainCounts 的一些注意事项: 进入方法:self.myList has retainCount = 1 退出方法:self.myList has retainCount = 2 and itemsToKeep has retainCount= 2. 我可以很容易地在最后做一个 [itemsToKeep release]两者都倒计时到 1,但应用程序在一段时间后崩溃(我想我知道为什么)。
有谁知道我怎样才能摆脱 itemsToKeep 的内存泄漏?
谢谢。
-(void)parsedScores:(BOOL)shouldAdd {
//trim space, tab, newline from both ends
NSString *tmp = self.lblCurrentName.text;
NSString *list = [self trimString:tmp];
NSString *separators = @",";
[self.myList removeAllObjects]; // doesn't impact retain counts
self.myList = (NSMutableArray *)[list componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:separators]]; //this bumps up the self.myList retain count to 2
NSMutableArray *itemsToKeep = [NSMutableArray arrayWithCapacity:30];
for (NSString *item in self.myList) {
NSString *tmpItem = [self trimString:item];
if (! [self shouldRemoveItem:tmpItem]) {
[itemsToKeep addObject:tmpItem];
}
}
self.myList = itemsToKeep; //makes both variables' retain counts = 2
}