iPhone - Objective-C Memory Leak with SBJsonParser

試著忘記壹切 提交于 2019-12-06 19:37:25

By commenting out the body of your if (line 50) you've made your release (line 51) conditional. Comment out the if (line 49) as well.

However, having said that your previous method has the same issue but apparently no warning, or maybe it was never used?

As CRD said above. You have the same leak in your JSONFragmentValue. Here is a correct non leaking version.

- (id) JSONFragmentValue
{
    SBJasonParser *jsonParser = [SBJasonParser new];
    id repr = [jsonParser fragmentWithString:self];
    if (repr == nil)
    {
        NSLog(@"JSonFragmentValue failed:%@", [jsonParser ErrorTrace]);
    }
    [jsonparser release], jsonParser = nil;
    return repr;
}

Or if you prefer autorelease pools.

- (id) JSONFragmentValue
    {
        SBJasonParser *jsonParser = [SBJasonParser new] autorelease];
        id repr = [jsonParser fragmentWithString:self];
        if (repr == nil)
        {
            NSLog(@"JSonFragmentValue failed:%@", [jsonParser ErrorTrace]);
        }
        return repr;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!