Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Leaks - Returning NSMutableArray from class method containing Custom Objects
    text
    copied!<p>I am using DBManager Class to retrun data from SQlite database. The class contains methods which returns MutableArray by fetching it from database. like bellow ..</p> <pre><code>+ (NSMutableArray *) getSaleForYear : (NSString *) year { if ([DBManager openDBConnection]) { NSMutableArray * sales = [[NSMutableArray alloc] initWithCapacity:1]; const char *q = "SELECT sales, quarter FROM sale where year like ? order by quarter"; sqlite3_stmt *selectstmt; if (sqlite3_prepare_v2(database, q, -1, &amp;selectstmt, NULL) == SQLITE_OK) { if(sqlite3_bind_text(selectstmt, 1, [year UTF8String] , -1, SQLITE_TRANSIENT) != SQLITE_OK){ NSLog(@"bind error : %@", [NSString stringWithUTF8String: sqlite3_errmsg(database)]); return nil; } while(sqlite3_step(selectstmt) == SQLITE_ROW) { float sale = sqlite3_column_double(selectstmt, 0); //NSString * quarter = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]; NSString * quarter = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]; ChartData * b1 = [[ChartData alloc] initwithdata:quarter y:sale]; [sales addObject:b1]; [b1 release]; [quarter release]; } } sqlite3_finalize(selectstmt); [DBManager closeDBConnection]; return [sales autorelease]; }else { return nil; } } </code></pre> <p>And I am calling the method like.</p> <pre><code>- (IBAction) getData { NSLog(@"getdata"); if (arr != nil) { for (ChartData * cd in arr) { [cd release]; } arr = nil; [arr release]; } arr = [[DBManager getSaleForYear:@"2010-11"] copy]; NSLog(@"count %d ", [arr count]); } </code></pre> <p>This approach is creating memory leaks for iterative calls of the function. Please suggest cause of the leak and solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload