iPhone SDK:How can I fix this leakage?

后端 未结 1 1385
再見小時候
再見小時候 2021-01-29 13:14

I have a leakege here but couldnt find the problem;

@property (nonatomic,retain) NSMutableData *responseXMLData;
@property (nonatomic,copy) NSMutableData *lastLo         


        
相关标签:
1条回答
  • 2021-01-29 14:06

    Without seeing your dealloc method, we cannot be sure you are correctly releasing the values of these properties.

    But in the posted code, I do see one major problem. But it's not where you think.

    self.lastLoadedResponseXMLData = docTempData;
    

    This line, although flagged by XCode, is fine (assuming you release the value correctly in dealloc).

    self.responseXMLData = [self.lastLoadedResponseXMLData copy];
    

    This line, however, is not fine. It makes a copy of whatever value is in self.lastLoadedResponseXMLData but you never release the reference due to the copy. self.responseXMLData, since it is declared "retain", adds its own reference to the object, and (assuming you release the value correctly in dealloc) this reference is the one cleaned up.

    If you don't really need to care whether the object is the same or is a copy, just forgo the copy. Otherwise, autorelease it:

    self.responseXMLData = [[self.lastLoadedResponseXMLData copy] autorelease];
    
    0 讨论(0)
提交回复
热议问题