我的應用程序工作正常,但是當我檢查是否有泄漏運行工具,它讓我在這行代碼泄漏,紫色與100.0%大關:內存泄漏的代碼
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
下面是一個包含此行的方法:
-(NSString*) languageSelectedStringForKey:(NSString*) key
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"zh" ofType:@"lproj"];
if(selectedLanguage==French)
{
FinalString = [[NSString alloc] initWithFormat:@"http://www.xyz.com/api_com.php?page_id=%d",IDValue];
url = [[NSURL alloc] initWithString:FinalString];
}
else if(selectedLanguage==German)
{
FinalString = [[NSString alloc] initWithFormat:@"http://www.x.com/api_com.php?page_id=%d",IDValue];
url = [[NSURL alloc] initWithString:FinalString];
}
else if(selectedLanguage==Nepali)
{
FinalString = [[NSString alloc] initWithFormat:@"http://www.xy.com/api_com.php?page_id=%d",IDValue];
url = [[NSURL alloc] initWithString:FinalString];
}
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[url release];
//Initialize the delegate.
parser = [[NewsParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
return str;
}
這裏是我的ViewDidLoad
方法從languageSelectedStringForKey
被調用。
- (void)viewDidLoad
{
// Do any additional setup after loading the view from its nib.
appDelegate = (ProgAppDelegate *)[[UIApplication sharedApplication] delegate];
IDValue = 1;
textLabel.text=[self languageSelectedStringForKey:@"Welcome to Advance Localization"];
[super viewDidLoad];
}
是什麼導致這個泄漏,我該如何解決?
這是dealloc方法: -
- (void)dealloc
{
[xmlParser release];
[parser release];
[nibLoadedCell release];
[super dealloc];
}
你是否在使用iOS 6的設備上進行泄漏分析?我有一個類似的泄漏,當用iOS 5分析設備時,泄漏消失。所以它可能指向Apple的源代碼中的問題? – iMathieuB