NSXMLParser 's delegate and memory leak
Posted
by dizzy_fingers
on Stack Overflow
See other posts from Stack Overflow
or by dizzy_fingers
Published on 2010-05-05T21:48:52Z
Indexed on
2010/05/05
21:58 UTC
Read the original article
Hit count: 216
Hello, I am using a NSXMLParser class in my program and I assign a delegate to it. This delegate, though, gets retained by the setDelegate: method resulting to a minor, yet annoying :-), memory leak.
I cannot release the delegate class after the setDelegate: because the program will crash.
Here is my code:
self.parserDelegate = [[ParserDelegate alloc] init]; //retainCount:1
self.xmlParser = [[NSXMLParser alloc] initWithData:self.xmlData];
[self.xmlParser setDelegate:self.parserDelegate]; //retainCount:2
[self.xmlParser parse];
[self.xmlParser release];
ParserDelegate is the delegate class.
Of course if I set 'self' as the delegate, I will have no problem but I would like to know if there is a way to use a different class as delegate with no leaks.
Thank you in advance.
© Stack Overflow or respective owner