Je développe sur iOS 4 et j'ai cette méthode dans mon appDelegate. Il est appelé à partir d'un couple de délégués de sources de données de tablesviews. Instruments m'a donné ces (sur l'appareil et le simulateur) Malloc 512 octets, Malloc 512 octets, NSConcreteMapTable (Fondation). Les mallocs ne montrent aucune bibliothèque responsable.fuite de mémoire iPhone lorsque la méthode renvoie l'objet
est ici la méthode de retour l'objet:
- (NSXMLParser *) getXmlParserFrom:(NSString *)remoteFile andCacheToFile:(NSString *) fileName forceRefresh:(BOOL) doRefresh {
NSXMLParser *xmlParser;
//FIRST TRY TO LOAD THE XML FROM CACHED FILE
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
NSString *xmlDocumentFromCache = [[NSString alloc] initWithContentsOfFile:filePath];
if (xmlDocumentFromCache && !doRefresh) {
NSData *xmlData = [NSData dataWithContentsOfFile:filePath];
xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
} else {
NSURL *xmlFileURL = [NSURL URLWithString:remoteFile];
NSString *contentsOfRemoteFile = [NSString stringWithContentsOfURL:xmlFileURL];
//CACHE THE FILE
BOOL cacheResult = [contentsOfRemoteFile writeToFile:filePath atomically:YES];
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlFileURL];
}
[xmlDocumentFromCache release];
return [xmlParser autorelease];
}
Dup de [NSXMLParser qui fuit] (http://stackoverflow.com/questions/1598928/nsxmlparser-leaking). Fondamentalement, c'est un bug (# 6469143) dans NSXMLParser. Devrait être réparé dans une prochaine version d'iOS. Vérifiez les réponses à la question liée pour les solutions de contournement. Lisez aussi ["NSXMLParser * rssParser provoque une fuite de mémoire"] (http://www.iphonedevsdk.com/forum/iphone-sdk-development/4910-nsxmlparser-rssparser-causing-memory-leak.html) sur iPhon Dev SDK. Googling "NSConcreteMapTable NSXMLParser" apparaîtra d'autres pages sur le bug. – outis