ios内存泄漏

时间:2011-10-18 21:59:23

标签: iphone objective-c ios memory-leaks nsxmlparser

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

这是我第一次使用instriments尝试解决内存泄漏并将其归结为违规方法..

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

我希望你能告诉我内存泄漏在哪里...因为我发布了myDataArray和解析器...我只是不确定我哪里出错了...我还需要分配它们吗?< / p>

- (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)

1 个答案:

答案 0 :(得分:2)

尝试将其放入.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];
}