probleme leak avec instrument parseur xml

paddevpaddev Membre
novembre 2011 modifié dans Apple Developer Programs #1
Bonjour a tous,

je suis entrain de faire une appli ou je parse plusieurs fichiers xml donc j'utilise dans mon appDelegate ces 2 fonctions plusieurs fois .
Avec instruments j'ai un leak de 100% sur cette ligne dans la fonction "checkforupadate"qui permet de verifier la date de mon fichier xml pour mettre a jour le flux rss:
TBXML *tbxml=TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www..........." retain];

instruments l'indique un leak: Malloc 128 bytes dans la lybrary libdispatch.dylib

Merci pour votre aide.

Voici le code des 2 fonctions:

<br />-(void)loadXML{<br />&nbsp; &nbsp; TBXML *tbxml=[[TBXML tbxmlWithURL:[NSURL URLWithString:@&quot;http://www.........&quot;]] retain];<br />&nbsp; &nbsp; TBXMLElement *root=tbxml.rootXMLElement;<br />&nbsp; &nbsp; [tbxml release];<br />&nbsp; &nbsp; if(root){<br />&nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *channel = [TBXML childElementNamed:@&quot;channel&quot; parentElement:root];<br />&nbsp; &nbsp; &nbsp; &nbsp; if(channel){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *item=[TBXML childElementNamed:@&quot;item&quot; parentElement:channel];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(item){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while(item !=nil){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *titre=[TBXML childElementNamed:@&quot;title&quot; parentElement:item];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSString *titreArt=[TBXML textForElement:titre];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *datePub=[TBXML childElementNamed:@&quot;pubDate&quot; parentElement:item];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSString *datePubArt=[TBXML textForElement:datePub];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *lien=[TBXML childElementNamed:@&quot;link&quot; parentElement:item];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSString *lienArt=[TBXML textForElement:lien];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *description=[TBXML childElementNamed:@&quot;description&quot; parentElement:item];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSString *desArt=[TBXML textForElement:description];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *image=[TBXML childElementNamed:@&quot;img&quot; parentElement:item];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLAttribute * attribute = image-&gt;firstAttribute;&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [[TBXML attributeName:attribute] isEqualToString: @&quot;src&quot;]; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSString *currencyName = [TBXML attributeValue:attribute]; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSURL *url = [NSURL URLWithString:currencyName];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSData *data = [[NSData alloc] initWithContentsOfURL:url];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIImage *uiImage = [UIImage imageWithData:data];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSData * imageData = UIImagePNGRepresentation(uiImage);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [data release];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; News *uneNews = (News *)[NSEntityDescription insertNewObjectForEntityForName:@&quot;News&quot; inManagedObjectContext:managedObjectContext_];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [uneNews setTitre:titreArt];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [uneNews setLien:lienArt];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [uneNews setDatePub:datePubArt];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [uneNews setDescription:desArt];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;  [uneNews setCategorie:catArt];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [uneNews setImage:currencyName];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [uneNews setImageBrut:imageData];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if([managedObjectContext_ save:nil]){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&quot;Enregistrement de la news&quot;);&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item=[TBXML nextSiblingNamed:@&quot;item&quot; searchFromElement:item];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; else{<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; }<br />}<br /><br /><br /><br /><br />-(void)checkForUpdate{<br />&nbsp; &nbsp; NSFetchRequest *dateRequest=[[NSFetchRequest alloc]init];<br />&nbsp; &nbsp; NSEntityDescription *dateEntity = [NSEntityDescription entityForName:@&quot;Update&quot; inManagedObjectContext:managedObjectContext_];<br />&nbsp; &nbsp; [dateRequest setEntity:dateEntity];<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; NSMutableArray *result=[[managedObjectContext_ executeFetchRequest:dateRequest error:nil]mutableCopy];<br />&nbsp; &nbsp; [dateRequest release];<br />&nbsp; &nbsp; dateBase=[[NSString alloc]init];<br />&nbsp; &nbsp; [glow=red,2,300]<br />&nbsp; &nbsp; TBXML *tbxml=[[TBXML tbxmlWithURL:[NSURL URLWithString:@&quot;http://www...........&quot;]] retain];&nbsp; // ICI LEAK 100%[/glow]<br />&nbsp; &nbsp; TBXMLElement *root=tbxml.rootXMLElement;<br />&nbsp; &nbsp; [tbxml release];<br />&nbsp; &nbsp; dateXMl=[[NSString alloc]init];<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; if(root){<br />&nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *channel = [TBXML childElementNamed:@&quot;channel&quot; parentElement:root];<br />&nbsp; &nbsp; &nbsp; &nbsp; if(channel){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBXMLElement *lastBuildUpdate=[TBXML childElementNamed:@&quot;lastBuildDate&quot; parentElement:channel];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(lastBuildUpdate){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dateXMl=[TBXML textForElement:lastBuildUpdate];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />	if([result count] == 0) {<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; Update *updateBase=(Update *) [NSEntityDescription insertNewObjectForEntityForName:@&quot;Update&quot; inManagedObjectContext:managedObjectContext_];<br />&nbsp; &nbsp; &nbsp; &nbsp; [updateBase setLastBuildDate:dateXMl];<br />&nbsp; &nbsp; &nbsp; &nbsp; [managedObjectContext_ save:nil];<br />&nbsp; &nbsp; &nbsp; &nbsp; [self loadXML];<br />	}<br />&nbsp; &nbsp; else{<br />&nbsp; &nbsp; &nbsp; &nbsp; Update *resultBase=(Update *)[result objectAtIndex:0];<br />&nbsp; &nbsp; &nbsp; &nbsp; dateBase=[resultBase LastBuildDate];<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; if([dateBase isEqualToString:dateXMl]){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(Update*newDate in result){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [newDate setLastBuildDate:dateXMl];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [self deleteEntity:@&quot;News&quot;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [self loadXML];<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; [result release];<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <br />}

Réponses

  • paddevpaddev Membre
    novembre 2011 modifié #2
      Voici ce que m'affiche instruments:

    <br /><br /> 0 libsystem_c.dylib calloc<br />&nbsp;  1 libdispatch.dylib dispatch_source_create$VARIANT$up<br />&nbsp;  2 CFNetwork __CFURLCache::StartWorkerThreadAndOpenPersistentStore(__CFString const*, unsigned char)<br />&nbsp;  3 CFNetwork CFURLCacheCreate<br />&nbsp;  4 CFNetwork CFURLCacheCopySharedURLCache<br />&nbsp;  5 CFNetwork StorageSession::copyCacheStorage() const<br />&nbsp;  6 CFNetwork _CFURLRequestCopySessionCache(_CFURLRequest const*)<br />&nbsp;  7 CFNetwork URLConnectionClient::URLConnectionClient(URLConnection*, _CFURLRequest const*, CFURLConnectionClient_V1*, __CFDictionary const*)<br />&nbsp;  8 CFNetwork URLConnection::initialize(_CFURLRequest const*, CFURLConnectionClient_V1*, __CFDictionary const*)<br />&nbsp;  9 CFNetwork CFURLConnectionCreateWithProperties<br />&nbsp; 10 CFNetwork CFURLConnectionSendSynchronousRequest<br />&nbsp; 11 Foundation +[NSURLConnection sendSynchronousRequest:returningResponse:error:]<br />&nbsp; 12 Foundation -[NSString initWithContentsOfURL:encoding:error:]<br />&nbsp; 13 Foundation +[NSString stringWithContentsOfURL:encoding:error:]<br />&nbsp; 14 eleazar -[TBXML initWithURL:] /Users/annefevre/Desktop/eleazar/eleazar/TBXML/TBXML.m:89<br />&nbsp; 15 eleazar +[TBXML tbxmlWithURL:] /Users/annefevre/Desktop/eleazar/eleazar/TBXML/TBXML.m:52<br />&nbsp; 16 eleazar -[eleazarAppDelegate checkForUpdate] /Users/annefevre/Desktop/eleazar/eleazar/eleazarAppDelegate.m:542<br />&nbsp; 17 eleazar -[eleazarAppDelegate application:didFinishLaunchingWithOptions:] /Users/annefevre/Desktop/eleazar/eleazar/eleazarAppDelegate.m:99<br />&nbsp; 18 UIKit -[UIApplication _callInitializationDelegatesForURL:payload:suspended:]<br />&nbsp; 19 UIKit -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:]<br />
    
Connectez-vous ou Inscrivez-vous pour répondre.