iphone - Releasing NSArray containing NSDictionary objects -


I have difficulty finding my head around memory management in the following segment of code on iPhone SDK 3.1.

  // Create an array to maintain each PersonClass object under NSMutableArray * arrayToReturn = [[[NSMutableArray alloc] init] autorelease]; NSArray * arrayOfDictionaries = [auto generated online people]; [Maintain AraroffDects]; (Ns Dictionary * Dictionary in Array Of Dictionaries) {PersonClass * aPerson = [[person class Alok] init]; For (Dictionary of Ansstiing * Key [Dictionary] [if ([key Avltostring: [[Ansstiing alloc] initWithString: @ "FIRST_NAME"]]) a Pisrn. First Name = [Dictionary object Foreki key]; Else if ( [key isqualToString: [[NSString alloc] initWithString: @ "LAST_NAME"]]) aPerson.lastName = [dictionary objectForKey: key];} // add PersonClass object arrayToReturn array [arrayToReturn addObject: aPerson]; // PersonClass object release [APerson release];} return array array again;  

[self genergenOfPeople] method gives an array of NSDictionary objects Land each NSDictionary contains two keys object "FIRST_NAME" and the first name of a person as data related with "LAST_NAME" and last name. Code is looping through each dictionary object Oreofdenisi array and Apisrn (Prsonclas ) Assigning dictionary data to an object's contextual property. This object is then added to an array that comes back by this method.

When I run the tool I am getting leakage for the dictionary objects contained in the array opiums array. Maintains [dictionaryObject release] on calling [self Jenreshnoffipl] method as the calling object as it is added to the created array, which count on each NSDictionary object object 1 (Calculating the object in the array will have to maintain 2, but then my release decreases back to 1).

I think this leak is because I am not releasing the arrayOfDictionaries array, and thus the encryption objects are not released within the array. If I try to release the array at the end of the above section of the code, I get the error message "sent to the distributed charge" error. I understand why this is happening, because I have a dictionary item (which I'm specifying a page object data within the I'm releasing later), but I do not know where I can leave the arrayOfDictionaries array. In

Edit: under [self genergenOfPeople]

  - (NSArray *) generateDictionaryOfPeople {NSMutableArray * arrayFromDatabase = [[[NSMutableArray alloc] init] autorelease]; // ** Check the database for the database ** while (rows from the database are being returned) {// Announce a NSMutableDictionary object NSMutableDictionary * dictionary = [[NSMutableDictionary alloc] init]; // Loop through each column of the line (the column for this row) {columnTitle = title_of_column_from_database columnData = data_in_that_column_from_database // Dictionary add object [dictionary setObject: columnData forKey: columnTitle]; Release Objects [column name release]; [Column title release]; } // Add the NSMutableDictionary object to the array [arrayFromDatabase addObject: dictionary]; Release Objects [dictionary release]; } // Return the array return aerformament database; } << Code>   

I still get the original leak due to not releasing arrayOfDictionaries The array is being

This means that you forgot it in autorelease generDictionaryOfPeople .

You need to review.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -