Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Memory Leaks..!
View Single Post
Old 07-03-2009, 12:30 PM   #11 (permalink)
hcarsten
Registered Member
 
Join Date: Apr 2009
Posts: 13
Default

Quote:
Originally Posted by _mubashir View Post
Hi,
The leak happens right after ViewDidLoad->getData functions.
So my viewDidLoad calls getData which fetches the data from sqlite DB and create Provider Objects and stores them in a NSMutableArray declared in the appdelegate. Here is complete function

Code:
- (void)getData {
	  
	MRAAppDelegate *appDelegate = (MRAAppDelegate *)[[UIApplication sharedApplication] delegate];
		if(statementSelectProvider == nil){
		const char *sql = "SELECT ProviderMaster_WK, ProviderID, LastName, FirstName, IsNew, City FROM tblProvider WHERE Project_WK=?";
		if (sqlite3_prepare_v2(database, sql, -1, &statementSelectProvider, NULL) != SQLITE_OK)
		{NSAssert1(0, @"Failed to prepare database with message '%s'.", sqlite3_errmsg(database));}
		// Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
		// The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.   
	}

	sqlite3_bind_int(statementSelectProvider, 1, appDelegate.ProjectWK);
	
	// We "step" through the results - once for each row.
	while (sqlite3_step(statementSelectProvider) == SQLITE_ROW) {
		// The second parameter indicates the column index into the result set.
		int iD = sqlite3_column_int(statementSelectProvider, 0);
		NSString *PID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statementSelectProvider, 1)];
		NSString *LName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statementSelectProvider, 2)];
		NSString *FName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statementSelectProvider, 3)];
		BOOL isNew = sqlite3_column_int(statementSelectProvider, 4); 
		NSString *city = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statementSelectProvider, 5)];
		
		Provider *objProvider = [[Provider alloc] initWithTitle:iD ProviderID:PID LastName:LName FirstName:FName city:city isNew:isNew];
		[appDelegate addProvider:objProvider];
		
	
		[objProvider release];
		
		
	}
	
	// "reset" the statement 
	
	sqlite3_reset(statementSelectProvider);
	if(statementSelectProvider)
	{
		sqlite3_finalize(statementSelectProvider);
		statementSelectProvider=nil;
	}
}
Please suggest if anything is wrong

Thanks,
Mubashir
As a good practise you should also release your bindings (see Reset All Bindings On A Prepared Statement). I think the libsqlite3 will not release all resources as long the bindings are still active. Anyway sqlite3 is a "plain c" lib so it will not work with objective-c memory management. But maybe this helps

Carsten
hcarsten is offline   Reply With Quote
 

» Advertisements
» Online Users: 318
19 members and 299 guests
ADY, BdR, BrianSlick, Diegan, djohnson, Duncan C, F_Bryant, glenn_sayers, Herbie, ilmman, Joseph Nardone, M@realobjects, Profile, rob.mccarthy, rodgo, TheWebWizz, VikMyr, vogueestylee, yomo710
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,876
Threads: 89,225
Posts: 380,702
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jorge599
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.