iphone - Releasing 2 times? -


I'm confused about releasing the object that I first alloc / initialized and then copied. As far as I was deemed to be a memory management manual, I should allot the object by releasing the object twice and later I should have kept 2 values ​​in copying it? So the first release will be reduced from one to the other? If I release this twice, I am sent a message to the DLOK object. If I do this once, there is no problem in the application, but in my understanding of the Ogative C-MAM, there is one. Management :))))))

The only explanation that I can think of when you leave an object with a white reference, will it continue immediately so that no one will keep a count?

Snippet bellow xmlElement is confused ....

  // LSAPNIPPET for code for TouchXML (CXMLElement * Results Results Healing in Result) {NSMutableDictionary * xmlElement = [[ NSMutableDictionary alloc] init]; // Create a counter variable in the form of "int" int counter; // Add the code as a key and node value with the node names by the name of the current node (counter = 0; counter & lt; [resultAlement childCount]; counter ++) {// xmlElement Set Object: [[Education Element ChildItindex: Counter] String Value): [[Education Element ChildItindex: Counter] Name]]; } // add blogItem to the global blog entry array so that the scene can access it. [TempReturnedElements addObject: [xmlElement copy]]; [XmlElement release]; // [xmlElement release]; But no! }   

UPDATE: Entire method code:

  + (zero) runXPath: (NSString *) xPathExpression {CXMLDocument * rssParser = [[[CXML document alloc ] InitWithXMLString: xmlStringContent option: 0 error: zero] autorelage]; // rss parser NSArray * result node = create a new array object to experiment with the loop of results from the null; // Set the nodes array to insert the object for each instance of the node in our RSS feed result nodes = [[RSSPerser nodesForxpath: xpathexation error: zero]; NSMutableArray * tempReturnedElements = [[NSMutableArray alloc] init]; // To loop through each result to reach the actual data (Elements in the result result for CXMLElement * result) {// Make a temporary MutableDictionary to store item fields, which will eventually end in blog entries NSMutableDictionary * XmlElement = [[NSMutableDictionary alloc] in this]; // Create a counter variable in the form of "int" int counter; // Add the code as a key and node value with the node names by the name of the current node (counter = 0; counter & lt; [resultAlement childCount]; counter ++) {// xmlElement Set Object: [[Education Element ChildItindex: Counter] String Value): [[Education Element ChildItindex: Counter] Name]]; } // add blogItem to the global blog entry array so that the scene can access it. [TempReturnedElements addObject: [xmlElement copy]]; // ***** If I use, then crush: // ***** [tempReturnedElements addObject: [[xmlElement copy] autorelease]]; [XmlElement release]; } [LotojuegosAppDelegate Set MyReturnedXmlElements: [tempReturnedElements copy]]; [TempReturnedElements release];   

The rule is very simple: retain each alloc / init , copy or For the / code> you only have to call a or autores when you want to leave the ownership, you have only asked a alloc / init , therefore You can only call release .

This row:

  [tempReturnedElements addObject: [xmlElement copy]];   

should be written as:

  [tempReturnedElements addObject: [[xmlElement copy] autorelease]];   

The reason is: copy gives you a new object, the calculation / ownership of the objects indicated by xmlElement is unchanged, but the new object Now for you now you are responsible for releasing it. See the first paragraph in this answer: You have said the copy, you need to release it on the resulting item.

Comments