2011-07-03 1 views
3

Après des méthodes est appelée à partir didFinishLaunchingWithOptions, quand je lance sur les instruments méthode OpenDatabase provoquant des fuites .. s'il vous plaît me suggérer comment effacerfuites de mémoire lors de l'ouverture de la base de données SQLite

- (NSString*)getdestinationPath { 
    NSArray *pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
    NSString *doumentDirectoryPath=[pathsArray objectAtIndex:0]; 
    NSString *destinationPath=[doumentDirectoryPath stringByAppendingPathComponent:dataBaseName]; 
    NSLog(@"database path %@",destinationPath); 
    return destinationPath; 
} 




- (void)chkAndCreateDatbase { 
    NSFileManager *fileManger=[NSFileManager defaultManager]; 
    NSError *error; 
    NSString *destinationPath=[self getdestinationPath]; 
    if ([fileManger fileExistsAtPath:destinationPath]){ 
     //NSLog(@"database localtion %@",destinationPath); 
     return; 
    } 
    NSString *sourcePath=[[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:dataBaseName]; 
    [fileManger copyItemAtPath:sourcePath toPath:destinationPath error:&error]; 
} 





- (void)openDatabase { 
    path=[self getdestinationPath]; 
    if (sqlite3_open([path UTF8String], &database)==SQLITE_OK) // here leak is showing 
    { 
     NSLog(@"dataBaseOpen"); 
    } 
    else { 
     sqlite3_close(database); 
     NSLog(@"dataBaseNotOpen"); 
    } 
} 
+0

chaque fois que j'appelle à la base de données de cette méthode obtient cadre called.Responsible est sqlite3MemMalloc –

Répondre

2

Vous fuit, car vous » ne pas appeler sqlite3_close(database) lorsque vous obtenez SQLITE_OK.

if (sqlite3_open([path UTF8String], &database)==SQLITE_OK) 
{ 
    NSLog(@"dataBaseOpen"); 
    // leak happens here, do stuff then call sqlite3_close(database), or move it out of the if/else block. 

} 
else { 
    sqlite3_close(database); 
    NSLog(@"dataBaseNotOpen"); 
} 
+0

Merci johny qui était mon problème .. –

Questions connexes