另一个iPhone内存泄漏问题 [英] Another iPhone Memory leak issue

查看:83
本文介绍了另一个iPhone内存泄漏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsonParser上发生内存泄漏.

I have memory leak on jsonParser.

这是我的代码

- (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]; }

这是我收到的错误消息,在第192行分配并存储到'jsonParser'中的对象的潜在泄漏

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

请帮助.

推荐答案

+ new等效于[[SBJsonParser alloc] init]调用,因此您有责任释放jsonParser对象.在return语句中使用它时,修复泄漏的最简单方法是在创建后立即将其自动释放:

+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];

这篇关于另一个iPhone内存泄漏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆