【发布时间】:2011-04-15 08:00:58
【问题描述】:
当我使用 Instruments 分析以下代码时,它报告了变量 imageName 的泄漏:
//loadImagesFromPotatoesIndexesArray
-(void) loadImagesFromPotatoesIndexesArray{
//Load Textures from Disk
textures = [[NSMutableArray alloc] init];
//NSArray *masks = [[NSArray alloc] initWithArray:mainDelegate.masksArray];
for (int i = 0;i<[potatoesIndexesArray count];i++){
int imageNumber = [[potatoesIndexesArray objectAtIndex:i]intValue];
NSString *imageName = [[NSString alloc] initWithFormat:@"texture%d",imageNumber];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];
NSArray *pics = [[NSArray alloc] initWithObjects:
[self maskImage:image withMask:[mainDelegate.masksArray objectAtIndex:i]],
[self maskImage:image withMask:[mainDelegate.masksArray objectAtIndex:i]],
imageName,
nil];
[textures addObject:pics];
[image release];
[imageName release];
[pics release];
}
}
[potatoesIndexesArray count] = 16,所以我有 16 次 NSCFString 泄漏......但对我来说,代码尊重内存管理......显然不是! 我做错了什么?
【问题讨论】:
-
看起来正确。你在你的设备上测试了吗?使用模拟器时,有时会出现“假”泄漏。
标签: iphone memory-leaks nsstring