我的應用程序出現奇怪的問題。
當我打開我的應用程序在解析一個RSS提要並顯示在tableview中的結果,並沒有泄漏,但如果我按下刷新按鈕,它泄漏(很多):(NSXMLParser刷新漏洞
我的項目:Link
代碼:
viewDidLoad中
UIBarButtonItem *ShareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(tableView_ReFresh)];
self.navigationItem.rightBarButtonItem = ShareButton;
[ShareButton release];
viewDidAppear
if ([stories count] == 0) {
NSURL *path = [[NSURL alloc] initWithString:@"http://feeds.feedburner.com/TheAppleBlog"];
[self parseXMLFileAtURL:path];
[path release];
}
tableView_ReFresh
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *path = [[NSURL alloc] initWithString:@"http://feeds.feedburner.com/TheAppleBlog"];
[self parseXMLFileAtURL:path];
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[path release];
[pool drain];
reloadData
[blogTable reloadData];
parseXMLFileAtURL
stories = [[NSMutableArray alloc]init];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSData *xml = [NSData dataWithContentsOfURL:URL];
rssParser = [[NSXMLParser alloc] initWithData:xml];
[rssParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser setDelegate:self];
[self.view setNeedsDisplay];
[rssParser parse];
[xml release];
didStartElement
currentElement = [[elementName copy]autorelease];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
item = [[[NSMutableDictionary alloc] init]autorelease];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentContent = [[NSMutableString alloc] init];
currentPostID = [[NSMutableString alloc] init];
currentCommentLink = [[NSMutableString alloc] init];
currentCommentNum = [[NSMutableString alloc] init];
}
didEndElement
個if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentPostID forKey:@"link"];
[item setObject:currentContent forKey:@"Content"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentCommentLink forKey:@"commentRssLink"];
[item setObject:currentCommentNum forKey:@"commentsNum"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentPostID);
//NSLog(@"adding story: %@", currentContent);
}
foundCharacters
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"guid"]) {
[currentPostID appendString:string];
} else if ([currentElement isEqualToString:@"content:encoded"]) {
[currentContent appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
} else if ([currentElement isEqualToString:@"wfw:commentRss"]) {
[currentCommentLink appendString:string];
} else if ([currentElement isEqualToString:@"slash:comments"]) {
[currentCommentNum appendString:string];
}
parserDidEndDocument
[blogTable reloadData];
的dealloc
[super dealloc];
[currentElement release];
[rssParser release];
[stories release];
[item release];
[currentTitle release];
[currentDate release];
[currentContent release];
[currentPostID release];
[currentCommentLink release];
[currentCommentNum release];
我該如何解決這個問題? 謝謝
它不工作:(你能看看我的項目嗎?謝謝 – user535351 2011-03-21 02:16:52
@ user535351對不起,我沒有時間看你的項目。同時,你看了我給你的建議(運行Build&Analyze看看它說了什麼)?你有沒有讀過關於內存管理的Apple文檔? – 2011-03-21 03:11:34