How to manage the Memory Leaks at the time of access the database?
<p>Iam developing one application.In that iam using one array for return the array of values in one function for getting the data from database.And allocate the memory for that one and use the autorelease.But that was killed at the time of execute that line.When iam release that one in dealloc function app will be crashed.If u dont use autorelease and release then memory leaks will be occured.sample for that function is below.</p>

<pre><code>-(NSMutableArray*)getWeeklyTableInfo:(int)month:(int)week
  {
     NSString *query = [NSString stringWithFormat:@"SELECT * FROM CalendarEvents where   Mont=%d and Week=%d ",month,week];
    sqlite3_stmt *stStatement;
     EventsArray1 = [[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [query UTF8String], -1, &amp;stStatement, nil)==SQLITE_OK)
    {
      while (sqlite3_step(stStatement)==SQLITE_ROW) {
            databasefields = [[DataBaseFields alloc]init];
            databasefields.DBSno=sqlite3_column_int(stStatement, 0);
            databasefields.DBdate =[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 1)];
            databasefields.DByear=sqlite3_column_int(stStatement, 2);
            databasefields.DBmonth=sqlite3_column_int(stStatement, 3);
            databasefields.DBweek=sqlite3_column_int(stStatement, 4);
            databasefields.DBtitle = [NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 5)];
            databasefields.DBlocation = [NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 6)];
            databasefields.DBtime = [NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 7)];
            databasefields.DBrepeat=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 8)];
            databasefields.DBalert=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 9)];
            databasefields.DBnotes=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 10)];
            databasefields.DBaudio=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 12)];
            databasefields.DBpicture=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 11)];
            databasefields.DBPhoneNO=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 13)];
            databasefields.DBMailID=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 14)];
            [EventsArray1 addObject:databasefields];
            [databasefields release];
        }
        if (stStatement!= nil) {
            sqlite3_finalize(stStatement);
        }
    }

sqlite3_close(database);
return EventsArray1;
</code></pre>

<p>}</p>

<p>so please tell me how to do that one.</p>
