我正在努力尋找在我的方法被調用後釋放數組的正確方法。我不知道是否有更好的方法來達到我想要用我的方法來acheive:與內存管理苦苦掙扎,並創建數組方法
- (NSArray *) setupDetailArray : (NSString *) selectedCategory {
// Load .plist file
NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
// Load .plist into a new dictionary
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
// Drill down to next level
NSArray *faceSelection = [[NSArray alloc] initWithArray:[dict objectForKey:detailTitle]];
[dict release], dict = nil;
// Set up link to App Delegate
UltimateRageAppDelegate *dataCenter = (UltimateRageAppDelegate *) [[UIApplication sharedApplication] delegate];
dataCenter.faces = [[NSMutableArray alloc] init];
// Set app delegate faces to array
dataCenter.faces = faceSelection;
[dataCenter.faces release];
return faceSelection;
// [faceSelection release], faceSelection = nil; ??????
}
,我打電話給我在viewDidLoad方法
// If faceArray is empty, create it
if (faceArray == nil)
faceArray = [self setupDetailArray:detailTitle];
...
我的應用程序在這裏泄漏內存,和我一直在尋找一種方式來釋放一切。
好的,我會的。由於我是全新的,因此我與該文檔進行了鬥爭。我相信總有一天它會有道理! – squarefrog
你只需要一遍又一遍地閱讀它,儘量找到儘可能多的例子。最終它是有道理的! –
感謝您對Nick Bull的投票! – squarefrog