user1138045
user1138045

Reputation: 11

How to release the NSXmlParser Object?

iam working on one application.In that application,i declared the NSXmlParser object in viewdidload method.But where this object can be release.So please tell me which is the correct place for release that object.See my code

NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"xml"];
NSData *data=[NSData dataWithContentsOfFile:xmlFilePath];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:self];
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:NO];
[xmlParser parse];

Upvotes: 0

Views: 63

Answers (2)

MadhavanRP
MadhavanRP

Reputation: 2830

You can release it right after the parse method is called

[xmlParser parse];
[xmlParser release];

Note that parse returns YES if successful and NO if not. So you might want to do some related operations before you release.

Upvotes: 1

Rohan
Rohan

Reputation: 2935

you can relese the xmlParser in -(void)dealloc method.

Upvotes: 0

Related Questions