輔助線程我調用一個函數與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調用。
您收到的消息與使用NSAutoreleasePool無關。它似乎是從輔助線程更新UI元素,但它應該只在主線程上執行。 – Vladimir 2010-07-23 15:17:04
準確地說,我打電話 [textView performSelectorOnMainThread:@selector(setText :) withObject:@「test」waitUntilDone:YES]; 但是這樣做不正確?因爲如果我不放這行,我沒有控制檯中的消息。 – alex 2010-07-23 15:28:59
你有一個名爲'padderChaine :::'和'concatener:chaine2:chaine3:chaine4:'的方法嗎?好惡!不要這樣做!交錯參數旨在由每個參數冒號前面的選擇器部分來描述。 – bbum 2010-07-23 17:39:28