I was getting a segfault 11 memory access error in the IOS Simulator, but it disappears when I comment out the release in the code below.
// get get the question number
NSString *text = [attributeDict valueForKey:XML_TAG_QUESTION_ATTRIBUTE开发者_运维知识库_NUMBER];
question.number = [text intValue];
//[text release]; <==== no more segfault 11 when this is commented out.
My question is, since I am receiving an instance of NS String returned by the NSXMLParser
implementation, isn't the reference count increased and should I not be releasing it?
Here's the rule: Always NARC on your memory management.
If you call:
(N)ew
(A)lloc
(R)etain or
(C)opy...
You need to release. If not, you got it through a convenience method and it's autoreleased.
In the case of containers of other objects, the container has the objects retained, and you don't need to worry about it until you release the container.
No it should not.
Read the memory management programming guide : http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html
精彩评论