【发布时间】:2012-10-29 13:08:47
【问题描述】:
我正在处理 JSON 数据解析,其中包含大量图像下载和数据解析。我有以下解析代码
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc] initWithData:webdata encoding:NSASCIIStringEncoding];
[webdata release];
[connection release];
NSDictionary *values = [(NSDictionary*)[responseString JSONValue] objectForKey:@"UserId"];
NSDictionary *Active = [(NSDictionary*)[responseString JSONValue] objectForKey:@"Active"];
[responseString release];
NSString *UserID=[NSString stringWithFormat:@"%@",values];
NSString *Status=[NSString stringWithFormat:@"%@",Active];
[WSDelegate WServiceResponseMsg:@"WS_Authenticate_User" withResponse:UserID forParam:Status];
}
我有许多类使用上述代码进行解析,但由于 SBJSON 解析器,应用程序在一段时间后崩溃。在仪器中,由于内存不足警告,应用程序崩溃。
【问题讨论】:
-
考虑使用 ARC(自动引用计数)。没有理由不这样做。它使 iOS 编码更加方便,并且很可能会解决您遇到的问题。
-
SBJson 3.1 需要 ARC 否则会泄漏。这不是 SBJson 中的错误。这里有很好的记录:github.com/stig/json-framework/blob/master/NEWS.md