Hi Richard - Here's my proof of concept, if you will. Open xCode, choose new project, choose Window-based application (the most basic) under the iPhone. In your application delegate class replace this method:
[code] - (void)applicationDidFinishLaunching:(UIApplication *)application { static sqlite3 *db; NSAutoreleasePool *mypool = [[NSAutoreleasePool alloc] init]; BOOL success; success = NO; NSFileManager *filemanager = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *mydbpath = [documentsDirectory stringByAppendingPathComponent:@"testdb.db"]; success = [filemanager fileExistsAtPath:mydbpath]; [filemanager release]; static sqlite3_stmt *init_statement = nil; if (sqlite3_open([mydbpath UTF8String], &db) == SQLITE_OK) { }else{ NSLog(@"Could not open db."); } if(success){ } else { const char *sql = "CREATE TABLE testtable(testc INTEGER)"; if (sqlite3_prepare_v2(db, sql, -1, &init_statement, NULL) != SQLITE_OK) { NSLog(@"Error: failed to prepare create statement with message %s.", sqlite3_errmsg(db)); } int success_sql = sqlite3_step(init_statement); if (success_sql == SQLITE_ERROR) { NSLog(@"Error: failed to CREATE into the database with message %s.", sqlite3_errmsg(db)); } sqlite3_reset(init_statement); } int i = 1; const char *sqltwo = "INSERT INTO testtable(testc) VALUES(?)"; int y = 0; for(y=0;y<1000;++y){ if (sqlite3_prepare_v2(db, sqltwo, -1, &init_statement, NULL) != SQLITE_OK) { NSLog(@"Error: failed to prepare create statement with message %s.", sqlite3_errmsg(db)); } sqlite3_bind_int(init_statement, 1, i); int success_sqltwo = sqlite3_step(init_statement); if (success_sqltwo == SQLITE_ERROR) { NSLog(@"Error: failed to CREATE into the database with message %s.", sqlite3_errmsg(db)); } sqlite3_reset(init_statement); } sqlite3_finalize(init_statement); sqlite3_close(db); [mypool release]; // Override point for customization after app launch [window makeKeyAndVisible]; } [/code] (oh, also make sure to add SQLite to the frameworks and add #import <sqlite3.h> to the app delegate .h file) Now, run it with instruments (I hope you agree by the time the window appears there should be no sqlite libs living, if not let me know what I've done wrong). It takes some looking, but if you switch the toggle to "created and still living" these do not disappear. (take a look at the attached JPG: http://www.bensmith.biz/instruments.jpg ) Thank you! Ben On Sat, Jul 26, 2008 at 11:24 AM, D. Richard Hipp <[EMAIL PROTECTED]> wrote: > > On Jul 26, 2008, at 2:12 PM, Ben Smith wrote: > >> Hi Folks - >> >> I have an issue (that others are reporting as well at Apple >> discussions); when using the built in SQLite3 library it seems that >> finalize and close doesn't actually release all of the memory of a >> particular connection. It isn't reported as a leak or anything. But >> if you use instruments you can see that the libsqlite3 is sitting >> there talking up memory (not a lot). It doesn't seem to have anything >> to do with what the db has in it or anything, it's just based on the >> number connections you have ever established (even if they have all >> been killed). >> >> >> Is this a known issue? Or am I doing something wrong (_close and >> _finalize are the only two de-constructors or is there something else >> I should be doing as well). > > > SQLite is carefully tested to ensure that all memory is released after > finalize & close. Such a memory leak would show up on all of our > standard tests and would be very in-your-face. It is not the kind of > thing we are likely to miss. I would be surprised to find that this > is something in the SQLite core. > > Are you certain that all prepared statements are finalized prior to > calling sqlite3_close()? > > I have no idea what kind of VFS layer is being used for the iPhone. > It might be something custom. If so, there could be a leak in the VFS > layer someplace. > > D. Richard Hipp > [EMAIL PROTECTED] > > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Ben Smith Founder / CSA WBP SYSTEMS http://www.wbpsystems.com _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users