2016-09-17 94 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]; 
}