我有我的viewDidLoad中下面几行:什么时候从viewDidLoad中的循环释放NSMutableArray?
self.sections = [[NSMutableDictionary alloc] init];
BOOL found;
// Loop through the signs and create our keys
for (NSDictionary *sign in self.allSigns)
{
NSString *c = [[sign objectForKey:@"name"] substringToIndex:1];
found = NO;
for (NSString *str in [self.sections allKeys])
{
if ([str isEqualToString:c])
{
found = YES;
}
}
// If string is not found, add it in uppercase to the sections array.
if (!found)
{ ** Potential leak of an object.**
[self.sections setValue:[[NSMutableArray alloc] init] forKey:[c uppercaseString]];
}
[sign release];
}
// Loop again and sort the signs into their respective keys
for (NSDictionary *sign in self.allSigns)
{
NSString *dummy = [[sign objectForKey:@"name"] substringToIndex:1];
[[self.sections objectForKey:[dummy uppercaseString]] addObject:sign];
}
// Sort each section array
for (NSString *key in [self.sections allKeys])
{
[[self.sections objectForKey:key] sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]];
}
//self.numberOfEntries = [[allSigns allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
[dataLoader release];
[super viewDidLoad];
后来我用不同的tableview委托方法的self.sections阵列。它也在我的头文件中正确声明,并且(当然)合成。
但是当我运行生成&分析,Xcode告诉我有一个对象的潜在泄漏。但我不知道我应该在哪里发布这个NSMutableArray,因为我不知道,例如,对象的名称。
我应该把它放在我的dealloc中,还是在循环之后释放它?
与问候,
拉特格