0
我有一個奇怪的問題得到解決,如果我在代碼中放置一個NSLog語句。 我有一個帶搜索欄的UITableviewController。我做最初取來填充表的方式如下:與NSAutoreleasepool和NSLog的奇怪問題
NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc]init];
self.listContent = [MainFunctions populateArrayFromModel]; //Get the array populated here from the model data
[pool2 release];
內MainFunctions的靜態方法,填充該數組像這樣:
NSMutableArray *resultArray = [[[NSMutableArray alloc] init] autorelease];
MModel *mainModel = [[MModel alloc] init];
//get all results from FetchedResultsController
[mainModel release];
return resultsArray;
上面的代碼只能如果我遵循特定模式,即我需要先按相關選項卡。如果在我來到這裏之前轉到另一個選項卡,則此代碼因某種原因掛起。
但是,如果我在代碼中放置了一些NSLog語句,它將始終如一地工作。像下面一樣;
NSMutableArray *resultArray = [[[NSMutableArray alloc] init] autorelease];
NSLog(@"1");
MModel *mainModel = [[MModel alloc] init];
//get all results from FetchedResultsController
NSLog(@"2");
//....code here
NSLog(@"3");
//....code here
NSLog(@"4");
[mainModel release];
return resultsArray;
我試過把它放回去多次,它一直顯示相同的行爲。 NSLog做了什麼,我感到困惑。
欣賞任何指針。
NSLog創建自動發佈的字符串?如果你使用NSMutableArray * resultArray = [NSMutableArray array];會發生什麼; –
謝謝,但沒有運氣 – user542584