以下功能;“ProcessArrayForscrollView”读取发送url接收到的JSON数据;"urlProcess" 并将获取的数据值以 NSString 格式存储在 NSMutableArrays 中。
#import "SBJson.h"
#import "SBJsonStreamParser.h"
@implementation AllShowsViewController
NSURL *url = nil;
NSString * arrayDataString;
NSData *dataAllShowsView;
NSError *errorAllShowsView;
NSString *data_stringAllShowsView;
SBJsonParser *parserAllShowsView;
NSArray *data_arrayAllShowsView;
NSDictionary *itemNSDictAllShowsView;
NSMutableArray *thumbnailImageURLAllShows;
NSMutableArray *thumbnailShowCountAllShows;
-(void)ProcessArrayForscrollView{
thumbnailImageURLAllShows = [[NSMutableArray alloc] init];
thumbnailShowCountAllShows = [[NSMutableArray alloc] init];
dataAllShowsView = [[[NSData alloc] initWithContentsOfURL:urlProcess] autorelease];
errorAllShowsView = nil;
data_stringAllShowsView = [[[NSString alloc] initWithData:dataAllShowsView encoding:NSUTF8StringEncoding]autorelease];
parserAllShowsView = [[[SBJsonParser alloc] init] autorelease];
data_arrayAllShowsView = [[[NSArray alloc] initWithArray:[parserAllShowsView objectWithString:data_stringAllShowsView error:&errorAllShowsView]] autorelease];
for(itemNSDictAllShowsView in data_arrayAllShowsView){
arrayDataString = [NSString stringWithFormat:@"%@",[itemNSDictAllShowsView objectForKey:@"thumbnail_small"]]; //memory leak notification here
[thumbnailImageURLAllShows addObject: arrayDataString];
arrayDataString = nil;
arrayDataString = [NSString stringWithFormat:@"%@",[itemNSDictAllShowsView objectForKey:@"showcount"]]; //memory leak notification here
[thumbnailShowCountAllShows addObject: arrayDataString];
arrayDataString = nil;
}
}
-(void)dealloc{
[super dealloc];
}
- (void)viewDidUnload{
if(thumbnailImageURLAllShows != nil){
[thumbnailImageURLAllShows release];
thumbnailImageURLAllShows = nil;
}
if(thumbnailShowCountAllShows != nil){
[thumbnailShowCountAllShows release];
thumbnailShowCountAllShows = nil;
}
[super viewDidUnload];
}
@end
我运行代码以使用 Xcode 工具检查内存泄漏,并在两行出现泄漏。从上面的 viewController 切换后会通知此泄漏;“AllShowsViewController”到任何其他 viewController(有一个 nib 文件)。关于如何消除泄漏的任何建议都会非常有帮助。