Another iPhone Memory leak issue

喜夏-厌秋 提交于 2020-01-06 08:43:19

问题


I have memory leak on jsonParser.

Here is my code

- (id) objectWithUrl:(NSURL *)url {
SBJsonParser *jsonParser = [SBJsonParser new];
NSString *jsonString = [self stringWithUrl:url];

// Parse the JSON into an Object
return [jsonParser objectWithString:jsonString error:nil]; }

This is the error message I'm getting, potential leak of an object allocated on line 192 and stored into 'jsonParser'

Please help.


回答1:


+new is equivalent to the [[SBJsonParser alloc] init] call so you're responsible to release jsonParser object. As you use it in return statement the easiest way to fix leak will be to autorelease it right after creating:

SBJsonParser *jsonParser = [[SBJsonParser new] autorelease];


来源:https://stackoverflow.com/questions/7336604/another-iphone-memory-leak-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!