Note that there are some explanatory texts on larger screens.

plurals
  1. POARC autoreleases too early (?)
    primarykey
    data
    text
    <p>I have a method call in class A:</p> <pre><code>GDataXMLElement *infoElement = [self getElementFromFilePath:filePath]; NSString *testStringA = [infoElement attributeForName:@"someAttribute"].stringValue; </code></pre> <p>and the method implementation in class B:</p> <pre><code>-(GDataXMLElement*)getElementFromFilePath:(NSString*)filePath { NSData *xmlData = [NSData dataWithContentsOfFile:filePath]; GDataXMLDocument *infoXMLDoc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:nil]; NSArray *infoArray = [infoXMLDoc.rootElement elementsForName:@"test"]; GDataXMLElement *returnElement = (GDataXMLElement*)infoArray[0]; NSString *testStringB = [returnElement attributeForName:@"someAttribute"].stringValue; return returnElement; } </code></pre> <p>The <code>returnElement</code> at the end of the method in class B is perfectly initialized, and <code>testStringB</code> string contains the correct value. But in Class A, the contents of <code>InfoElement</code> are gone, and testStringA is nil. </p> <p>I suspect that ARC is releasing GDataXMLDocument too early, and was able to stop this behaviour by tying the document to a property in class B:</p> <pre><code>@property (nonatomic,strong) GDataXMLDocument *infoXMLDoc; </code></pre> <p>But I am a little unsatisfied with this solution. I'll never use that property again, I just need the element to parse it one time only. If it is possible to stop the release with a property, is there also a way to do this within the method? I tried the __strong qualifier like this:</p> <pre><code>GDataXMLDocument __strong *infoXMLDoc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&amp;error]; </code></pre> <p>but that didn't help. So my questions, assuming ARC is indeed responsible:</p> <p><strong>1. Is is possible to tell ARC within a method to not release an object?</strong></p> <p><strong>2. What did I not understand about the behaviour here?</strong> I am using ARC for some time now, this is the first time that I am stuck. </p>
    singulars
    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.
 

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