我正在做最後一點的內存管理整理,有些東西我不明白。我已經檢查了所有的文檔,堆棧溢出等,但仍然沒有得到它。我懷疑這是與數組有關的。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