views:

33

answers:

2

Hi,

I init my NSXMLParser with a mutable data, that I get from the internet. I wonder whether the parser releases it on its deallocation or I have to release it after the parsing?

Thanks

+1  A: 

If you have retained it, and you no longer use it, then release it. The NSXMLParser will most likely retain the data itself and release it when it is finished with it.

Mike Weller
Thanks for the answer, should I release it after parsing or it doesn't matter? I saw, that if i release it before, i get a crash on unknown selector and seems that the parser doesn't retain it
Nava Carmon
If you have retained it, you should release it once you are finished with it. That means after you have passed it to the NSXMLParser however.
Mike Weller
+2  A: 

Cocoa uses the "It's not my problem" metaphor to memory management.

If you pass something to another object, it is that objects responsibility to retain it.

If something is passed to one of your objects, you need to retain it or it may go away.

Generally pass objects like:

    [otherObject doSomethingWith:[myThing autorelease]];

OR

    [otherObject doSomethingWith:myThing];
    [myThing release];

The Cocoa frameworks work on this principle and you should design your classes the same way.

Corey Floyd