2010-07-23 61 views
0

輔助線程我調用一個函數與performSelectorInBackground,在此功能,我宣佈與nsautoreleasepool

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

之初

[pool release];   

但在控制檯中,我有這樣的信息:

2010-07-23 10:58:30.277 ProjetMission[5914:6913] void _WebThreadLockFromAnyThread(bool), 0x5d5c770: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread. 

爲什麼?因爲如果我不把nsautoreasepool在我的功能我有這樣大量的信息:

2010-07-23 11:02:58.667 ProjetMission[5951:660f] *** __NSAutoreleaseNoPool(): Object 0x5a7c560 of class NSCFString autoreleased with no pool in place - just leaking 

感謝您的幫助

-(void) telechargerDossierWebDansThread 
{ 

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    NSString *nomFichier; 
    int i; 
    BOOL dossierExiste = FALSE; 
    int y; 
    NSString *reponse; 

    NSArray *listeFichier = [self listeFichierATelecharger:[dossierWeb stringByAppendingString:@"/fichier-a-downloader.txt"]]; 

    [textView performSelectorOnMainThread:@selector(setText:) withObject:@"" waitUntilDone:YES]; 

    [textView performSelectorOnMainThread:@selector(setText:) withObject:[FonctionUtile concatener: @"Sommaire du download pour le circuit-" chaine2:nomCircuit chaine3:@"" chaine4:@"\n"] waitUntilDone:YES]; 
    [textView performSelectorOnMainThread:@selector(setText:) withObject:[FonctionUtile concatener:textView.text chaine2:@"Nombre de fichier à downloader => " chaine3:[NSString stringWithFormat:@"%d", [listeFichier count]] chaine4:@"\n"] waitUntilDone:YES]; 

    if ([listeFichier count] > 0) 
    { 

     if ([ManipulationFichierDossier supprimerDossierFichier:cheminDossierSurIpod] || ![ManipulationFichierDossier VerifierSiDossierFichierExiste:cheminDossierSurIpod]) { 
      dossierExiste = [ManipulationFichierDossier creerDossier:cheminDossierSurIpod]; 
     } 

     if (dossierExiste) 
     { 

      [textView performSelectorOnMainThread:@selector(setText:) withObject:[FonctionUtile concatener:textView.text chaine2:[FonctionUtile padderChaine:@"Fichiers à downloader" :27 :@" " :TRUE] chaine3:@"Download succès" chaine4:@"\n" ] waitUntilDone:YES]; 

      y = 70; 

      for (i = 0; i < [listeFichier count]; i++) 
      { 
       nomFichier = [[listeFichier objectAtIndex:i]retain]; 

       if ([self TelechargerFichierUnique:nomFichier :[FonctionUtile concatener:dossierWeb chaine2:@"/" chaine3:nomFichier chaine4:@""] :cheminDossierSurIpod :TRUE]) 
       { 

        reponse = @"Oui"; 
       } 
       else     
       { 
        reponse = @"Non"; 
       } 

       [textView performSelectorOnMainThread:@selector(setText:) withObject:[FonctionUtile concatener:textView.text chaine2:[FonctionUtile padderChaine:nomFichier :27 :@" " :TRUE] chaine3:reponse chaine4:@"\n"] waitUntilDone:YES]; 

       y = y +20; 
      } 
     } 
    } 

    [textView performSelectorOnMainThread:@selector(setText:) withObject:[FonctionUtile concatener:textView.text chaine2: @"Fin du download pour le circuit-" chaine3:nomCircuit chaine4:@""] waitUntilDone:YES]; 

    [pool release]; 
} 

而這個功能是通過performSelectorInBackground調用。

+1

您收到的消息與使用NSAutoreleasePool無關。它似乎是從輔助線程更新UI元素,但它應該只在主線程上執行。 – Vladimir 2010-07-23 15:17:04

+0

準確地說,我打電話 [textView performSelectorOnMainThread:@selector(setText :) withObject:@「test」waitUntilDone:YES]; 但是這樣做不正確?因爲如果我不放這行,我沒有控制檯中的消息。 – alex 2010-07-23 15:28:59

+2

你有一個名爲'padderChaine :::'和'concatener:chaine2:chaine3:chaine4:'的方法嗎?好惡!不要這樣做!交錯參數旨在由每個參數冒號前面的選擇器部分來描述。 – bbum 2010-07-23 17:39:28

回答

1

擁有NSAutoreleasePool是正確的。該錯誤消息似乎表明您正在從後臺線程操縱UI元素(可能是UIWebView)。正如錯誤信息所述,這不是一件好事™。

+0

爲什麼這不是一件好事? 這條線是在一個循環 [TextView的performSelectorOnMainThread:@selector(:)的setText withObject:@「測試」 waitUntilDone:YES] 我把這個輔助線程,因爲如果它是在主線程中的TextView只在刷新函數的結束。 – alex 2010-07-23 15:33:09

+0

@alex在主線程上操作,而不是後臺線程。錯誤消息似乎表明其他事情正在發生。也許你可以把身體或你的方法放在問題上? – 2010-07-23 16:09:22

+0

我把我的功能放在問題上! – alex 2010-07-23 16:26:26