この行で一定のメモリリークが発生しています
> 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;
}