次の関数は、 "ProcessArrayForscrollView"は、URLの送信によって受信されたJSONデータを読み取ります。 "urlProcess"を呼び出し、取り出されたデータ値をNSMutableArraysにNSString形式で格納します。NSPlaceholderString initWithFormat:locale:arguments:Xcode計測器リーク
#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計測器を使用してメモリリークをチェックするコードを実行し、2行でリークを検出しました。このリークは、上記のviewControllerから切り替えた後に通知されます。 "AllShowsViewController"を他のviewController(nibファイルを持つ)に渡してください。漏れを取り除く方法についてのアドバイスは本当に役に立ちます。
提案をいただきありがとうございます。残念ながら、いずれかのメソッドにコードを移動しても、同じ行にメモリリークがあります。以下は、リークの詳細です: **責任フレーム** - NSPlaceholderString initWithFormat:ロケール:引数: **責任ライブラリ** - 財団 –