2011-07-08 26 views
1

我似乎無法找出泄漏工具報告的問題的原因。有問題的代碼在這裏標有問題行。有任何想法嗎?有沒有辦法找出泄漏究竟是什麼物體?問題內核中的內存泄漏數據代碼

NSArray *getAllCoreData(NSString *entityName, NSString *orderedBy, BOOL ascending, BOOL shallow) 
{ 
// Get the managed object context 
NSManagedObjectContext *moc = [[AppController sharedAppController] managedObjectContext]; 

// Create a fetch request that fetches from 'entityName' 
NSFetchRequest *fetch = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:moc]; 
[fetch setEntity:entity]; 

// Try to do the fetch 
NSError *error; 
NSArray *result = [moc executeFetchRequest:fetch error:&error]; <----- Problem line 

[fetch release]; 

// Did the fetch fail? 
if (!result) 
{ 
    // Display an alert view 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Fetch Failed" 
                 message:[error localizedDescription] 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 

    [alertView autorelease]; 
    [alertView show]; 
    return nil; 
} 

// Return the array of instances of NSManagedObject 
return result; 
} 

任何幫助,將不勝感激, 傑森

+0

你好賈森,我也面臨類似的問題,所以你可以請張貼解決這個問題? – ujjawal

回答

1

泄漏告訴你的內存分配,你沒有更多的引用後有圍繞保持。

因此,在您返回結果後,其他內容會保留太長時間,並且在完成後不會釋放。

+0

你是對的!顯然隧道視野已經開始了,我看不到這個例程。我的理智感謝你。 – Jason

1

嘗試改變

NSError *error; 

NSError *error = nil; 

它可能不是一個真正的泄漏。可能NSError *error恰好在其中有一些剩餘指針,因此它看起來像是工具泄漏。

+0

這不是問題,但我也清理過了。謝謝。 – Jason