【发布时间】:2010-11-15 14:05:22
【问题描述】:
我有我的函数 getAllData,它返回一个带有字典的数组。
- (NSArray *)getAllData {
NSMutableArray *result = [[NSMutableArray alloc] init];
NSArray *data = [skiResorts sortedArrayUsingFunction:comparator context:NULL];
NSString *currentLetter = @"A";
NSMutableArray *array = [[NSMutableArray alloc] init] ;
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init] ;
if ([data count] > 0) {
for (SkiResort *resort in data) {
if ([resort.name hasPrefix:currentLetter]) {
// Same letter as before.
// Add current SkiResort to temporary array.
[array addObject:resort];
} else {
// New letter.
// Add previous header/row data to dictionary.
[dict setValue:currentLetter forKey:@"header"];
[dict setValue:array forKey:@"row"];
// Add dictionary to final result array.
[result addObject:dict];
// Startover ...
[array removeAllObjects];
[dict removeAllObjects];
// Prepare for next letter.
currentLetter = [resort.name substringToIndex:1];
// Add current SkiResort to temporary array.
[array addObject:resort];
}
}
// Add previous header/row data to dictionary.
[dict setValue:currentLetter forKey:@"header"];
[dict setValue:array forKey:@"row"];
// Add dictionary to final result array.
[result addObject:dict];
}
[array release];
[dict release];
return [result autorelease];
}
谁能在我的代码中看到明显的内存泄漏?我得到内存泄漏数组、字典和结果...
【问题讨论】:
标签: memory-leaks ios4 memory-management