2016-09-17 87 views
2

我在我的SQLiteManager.m實現中有以下方法。警告:舊的遺留代碼警報EXC_BAD_ACCESS on方法

- (void)dealloc { 
    [super dealloc]; 
    if (db != nil) { 
     [self closeDatabase]; 
    } 
    [databaseName release]; 
} 

- (NSError *) closeDatabase 
{  
    NSError *error = nil; 
    if (db != nil) { 
      // Set and log error somewhere, not relevant here 
     } 
     db = nil; 
    } 
    return error; 
} 

當我在iOS 10 iPad上以調試模式運行我的應用程序時,它運行正常。當我在iOS 10 iPad(具有開發證書和配置文件)上以發行模式運行我的應用程序時,該應用程序在線路[self closeDatabase];上崩潰,返回EXC_BAD_ACCESS。我在我的控制檯中看到self仍然是一個SQLiteManager對象。如何引用您自己班級的方法可能會導致訪問錯誤,並且僅在發佈模式下出現?

PS:當我使用NSZombieEnabled = YES運行時,該應用運行良好。

+0

崩潰線程的堆棧跟蹤是否顯示任何內容? (即在(lldb)提示符下鍵入'bt')。 –

+1

聲音就像你的SQLiteManager對象變成了殭屍。 – Kreiri

回答

1

我找到了我的答案。我必須將呼叫[super dealloc];置於覆蓋的dealloc方法的末尾。

- (void)dealloc 
{ 
    if (db != nil) { 
     [self closeDatabase]; 
    } 
    [databaseName release]; 
    [super dealloc]; 
}