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
我在一个应用程序上工作。在那个应用程序中,我在viewdidload方法中声明了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];
2 个解决方案
#1
0
you can relese the xmlParser in -(void)dealloc method.
你可以在 - (void)dealloc方法中释放xmlParser。
#2
1
You can release it right after the parse method is called
您可以在调用parse方法后立即释放它
[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.
请注意,如果成功则解析返回YES,否则返回NO。因此,您可能希望在发布之前执行一些相关操作。
#1
0
you can relese the xmlParser in -(void)dealloc method.
你可以在 - (void)dealloc方法中释放xmlParser。
#2
1
You can release it right after the parse method is called
您可以在调用parse方法后立即释放它
[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.
请注意,如果成功则解析返回YES,否则返回NO。因此,您可能希望在发布之前执行一些相关操作。