我在这条线上一直有内存泄漏
> if (sqlite3_open([databasePath UTF8String], &databaseHandle) != SQLITE_OK)
. 可能是什么原因 ??我什至在打开数据库后关闭了它。但它无济于事。
我的整个方法是
-(void)copyCustomDatabase{
/** done - @todo Copy db file from app resources */
@try {
NGMobileCaptureSingleton * singleton = [NGMobileCaptureSingleton getSharedInstance];
NSString *documentsDirectory = [singleton getAppDocumentDirectory];
NSString *apkIdStr = [NSString stringWithFormat:@"%d", [NGMobileCaptureSingleton getSharedInstance].apkId];
NSString *databaseName = [[[[@"ngcapcust_" stringByAppendingString:apkIdStr] stringByAppendingString:@"_"] stringByAppendingString:[NSString stringWithFormat:@"%d", formId]] stringByAppendingString:@".db"];
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:databaseName];
// NSLog(@"copyCustomDatabase Custom Database Path %@", databasePath);
bool databaseAlreadyExists = [[NSFileManager defaultManager] fileExistsAtPath:databasePath];
if (!databaseAlreadyExists)
{
NSError *error;
NSFileManager *fileManager = [[NSFileManager defaultManager] init];
NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:srcPath toPath:databasePath error:&error];
}
if (sqlite3_open([databasePath UTF8String], &databaseHandle) != SQLITE_OK)
{
[self closeDatabase];
NSLog(@"NGDefaultCustomHelper copyCustomDatabase Error in creating database handle");
// } else {
// NSLog(@"NGDefaultCustomHelper copyCustomDatabase Database handle created successfully");
}
} @catch (NSException *exception) {
NSLog(@"NGDefaultCustomHelper copyCustomDatabase exception : %@", exception);
}
}
- (void)closeDatabase
{
sqlite3_close(databaseHandle);
databaseHandle = NULL;
tableMap = NULL;
tableIdMap = NULL;
}