我正在做最后一点的内存管理整理,有些东西我不明白。我已经检查了所有的文档,堆栈溢出等,但仍然没有得到它。我怀疑这是与数组有关的。NSMutableArray实例变量内存管理
我有一个NSMutableArray
作为一个实例变量,我用它来保存从另一个数组中的对象创建的对象。
-viewDidLoad
初始化数组如下:
self.photoAlbum = [[NSMutableArray alloc] initWithCapacity:100];
它然后调用该填充它们的方法。
int i = 0;
for (Gem *gem in self.entityArray) {
NSString * filePath = [[NSString alloc] initWithFormat: @"%@/%@2.jpg", [sysPaths objectAtIndex: 0], gem.detailsTitle];
// there is some stuff in here that means that there isn't a one to one relationship between the objects in gem and those in photo
Photo *photo = [[Photo alloc] init];
photo.filePath = filePath;
photo.title = gem.title;
photo.index = [NSNumber numberWithInt:i];
[self.photoAlbum addObject:photo];
[filePath release];
[photo release];
i++;
}
仪表,它显示我泄露Photo
对象,我不知道为什么。
的photoAlbum
属性是:
@property (nonatomic, retain) NSMutableArray *photoAlbum;
我缺少什么?
+1为底部的大胆位! – walkytalky 2011-04-01 16:39:55
谢谢乔纳森。这是数组特有的吗?我的@property声明是最合适的吗? – Chris 2011-04-01 16:57:37
该代码吓了我一秒。 – bbum 2011-04-01 19:49:04