iphone - ios内存泄漏

标签 iphone objective-c ios memory-leaks nsxmlparser

我有一个方法可以使用正确的数据设置 NSXMLParser,我很确定会导致内存泄漏。

这是我第一次使用工具来尝试解决内存泄漏并将其归结为有问题的方法..

通过查看仪器内存泄漏测试中的响应调用者值。

我希望你能告诉我内存泄漏在哪里...因为我释放了 myDataArray 和解析器...我只是不确定我哪里出错了..我是否也需要将它们分配为零?

- (void)startTheParsingProcess:(NSData *)parserData
{
    [myDataArray release]; // clears array for next time it is used.
    myDataArray = [[NSMutableArray alloc] init];

    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process 

    [parser setDelegate:self];
    [parser parse]; // starts the event-driven parsing operation.
    [parser release];
}

如有任何帮助,我们将不胜感激。

更新:

我已经对我的应用程序进行了更改,当我在模拟器上运行它时,我没有收到任何内存泄漏错误。

但是,如果我在手机上运行它,请在控制台中获取它...

2011-10-19 11:22:05.673 code[1299:707] -[__NSCFType section]: unrecognized selector sent to instance 0x1b9b80
2011-10-19 11:22:05.683 code[1299:707] CoreAnimation: ignoring exception: -[__NSCFType section]: unrecognized selector sent to instance 0x1b9b80
2011-10-19 11:22:07.949 code[1299:707] -[__NSCFType row]: unrecognized selector sent to instance 0x1b9b80
2011-10-19 11:22:07.951 code[1299:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType row]: unrecognized selector sent to instance 0x1b9b80'
*** First throw call stack:
(0x35e9e8b3 0x366e61e5 0x35ea1acb 0x35ea0939 0x35dfb680 0x334a76cf 0x3353c713 0x30fd5 0x3352cd69 0x335a60ab 0x35cc32ab 0x35e72a57 0x35e726bd 0x35e71293 0x35df44e5 0x35df43ad 0x30fa4fed 0x334a7dc7 0x272f 0x26d8)

最佳答案

试着把它放在 .h 中

@property (nonatomic, retain) NSMutableArray *myDataArray

.m

@synthesize myDataArray

in the method...

- (void)startTheParsingProcess:(NSData *)parserData
{
    self.myDataArray = [NSMutableArray arrayWithCapacity:8];

    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process 

    [parser setDelegate:self];
    [parser parse]; // starts the event-driven parsing operation.
    [parser release];
}

关于iphone - ios内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7814259/

相关文章:

iphone - 如何设置蓝牙通信在后台运行

ios - iOS 6 是否支持 OpenSSL?

ios - 在 iOS 中使用 ARC 对 dealloc 进行单元测试

iphone - 无法设置UITabBarController的moreNavigationController的右键

ios - 在安装 iOS 应用程序时提醒用户所需的 iOS 版本

ios - 简单的计算器应用程序,当我添加新按钮时出现 SIGABRT 错误

c# - 使用 MonoTouch 在 iOS 上自定义 Switch

javascript - 在 sencha touch 中动态添加一个项目到工具栏

iphone - 如何在 iPhone Safari 中强制刷新 Web 应用程序文档?

iphone - 不想为 UITableViewCell 使用 dequeueReusableCellWithIdentifier