Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the function fetchDataForTierOne, first line myTierOneDict = [[NSMutableDictionary alloc]init]; is creating memory leak. You are creating a dictionary and assigned a different dictionary returned by getDataToDisplayTierOne function.</p> <p>So, the dictionary created in the first line of function fetchDataForTierOne will become unreferenced and will create a leak. No need to write first line.</p> <p>Second, return the dictionary with autorelease and retain it in fetchDataForTierOne function. After completing the usage release it.</p> <p>Updated Code:</p> <p>//===============================================================</p> <p>-( NSMutableDictionary * ) getDataToDisplayTierOne:(NSString*)dbPath{ //================================================================</p> <pre><code>NSMutableDictionary *aTierOneData = [[NSMutableDictionary alloc]init]; if (sqlite3_open([dbPath UTF8String], &amp;database) == SQLITE_OK) { const char *sql_query_stmt = "select * from main_categories"; sqlite3_stmt *selectstmt; if(sqlite3_prepare_v2(database, sql_query_stmt, -1, &amp;selectstmt, NULL) == SQLITE_OK) { while(sqlite3_step(selectstmt) == SQLITE_ROW) { NSString *aValue = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(selectstmt, 1)]; NSString *aId = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(selectstmt, 0)]; [aTierOneData setObject:aId forKey:aValue]; [aValue release]; [aId release]; } } } else{//Even though the open call failed, close the database connection to sqlite3_close(database); } return [aTierOneData autorelease]; </code></pre> <p>}</p> <p>-(void)fetchDataForTierOne{</p> <p>//===========================</p> <pre><code>myTierOneDict = [[myDBOperations getDataToDisplayTierOne:[appDelegate getDBPath]]retain]; NSArray *myTierOneDictKeys = [myTierOneDict allKeys]; myTierOneData = [[NSMutableArray alloc] initWithArray:(NSArray*)myTierOneDictKeys]; if ([myTierOneData count] &gt; 0 ){ [self constructTierOnePicker]; } </code></pre> <p>[myTierOneDict release]; }</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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