iPhone - SBJsonParser 的 Objective-C 内存泄漏
我使用 Xcode 中的“Leaks”工具不断收到以下内存泄漏信息。由于这是一个库,我只是想知道修复此类泄漏的最佳方法是什么。任何帮助将不胜感激。如果需要,我很乐意分享更多代码。
更新:我找到了这篇文章,它似乎没有希望。有人对如何解决这个问题有任何建议吗?
http://code.google.com/p/json- Framework/issues/detail?id=13
这就是我使用该库的方式。
- (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];
}
}
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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过注释掉 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?
正如CRD上面所说。您的 JSONFragmentValue 中也有同样的泄漏。这是一个正确的非泄漏版本。
或者如果您更喜欢自动释放池。
As CRD said above. You have the same leak in your JSONFragmentValue. Here is a correct non leaking version.
Or if you prefer autorelease pools.