iPhone-具有SBJsonParser的Objective-C内存泄漏 [英] iPhone - Objective-C Memory Leak with SBJsonParser

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

问题描述

我一直使用Xcode中的泄漏"工具来获取以下内存泄漏.由于这是一个库,我只是想知道什么是解决此类泄漏的最佳方法.任何帮助将不胜感激.如果需要,我很乐意分享更多代码.

I keep getting the following memory leak using the "Leaks" tool in Xcode. As this is a library, I'm just wondering what would be the best way to fix such a leak. Any help would be greatly appreciated. I am happy to share more code if needed.

更新:我找到了这篇文章,似乎不太有前途.有人对如何解决此问题有任何建议吗?

UPDATE: I found this article, which doesn't seem promising. Has anyone got any suggestions as to how to fix this?

http://code.google.com/p /json-framework/issues/detail?id = 13

这就是我使用图书馆的方式.

This is how I'm using the library.

- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request {
    NSString *responseString = [request responseString];
    NSMutableDictionary *responseJSON = [responseString JSONValue]; //memory leak 100%   

    NSString *username;
    NSString *firstName = [responseJSON objectForKey:@"first_name"];
    NSString *lastName = [responseJSON objectForKey:@"last_name"];
    NSString *facebookId = [responseJSON objectForKey:@"id"];
    if (firstName && lastName) {
        username = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
    } else {
        username = @"";
    }

    UIAppDelegate.userSessionId = facebookId;
    UIAppDelegate.userFullName = username;

    if (UIAppDelegate.userSessionId != nil) {
        Service1 *service = [[Service1 alloc] init];
        [service UserExists:self action:@selector(handlerUserExists:) facebookUserId:UIAppDelegate.userSessionId];
        [service release];
    } else {
        [Utility displayAlertMessage:@"There has been an error. Please try again later." withTitle:@"Error"];
        [self logoutCompletely];
    }
}

推荐答案

通过注释掉if(第50行)的主体,已使您的发布(第51行)成为条件.注释掉if(第49行).

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?

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

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