如何释放NSXmlParser对象?
问题描述:
一个application.In该应用程序IAM工作,我宣布viewDidLoad中的的NSXMLParser对象method.But哪里这个对象可以release.So请告诉我这是发行版object.See我的代码中的正确位置如何释放NSXmlParser对象?
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];
答
你可以在 - (void)dealloc方法中分解xmlParser。
答
可以释放解析方法称为
[xmlParser parse];
[xmlParser release];
注意parse
;是如果成功和NO如果不是之后。所以你可能想在发布之前做一些相关的操作。