Iphone 具有nsautoreleasepool的次线程

Iphone 具有nsautoreleasepool的次线程,iphone,objective-c,Iphone,Objective C,我使用performSelectorInBackground调用一个函数,在这个函数中,我声明 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 起初 [pool release]; 最后 但在控制台中,我有一条信息: 2010-07-23 10:58:30.277 ProjetMission[5914:6913] void _WebThreadLockFromAnyThread(bool), 0x

我使用performSelectorInBackground调用一个函数,在这个函数中,我声明

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];
}
-(void)TelecoChargerDossierWebDansThread
{
NSAutoreleasePool*池=[[NSAutoreleasePool alloc]init];
NSString*nomFichier;
int i;
BOOL dossierExiste=假;
int-y;
NSString*响应;
NSArray*ListFicheer=[self-ListFicherateCharger:[dossierWeb stringByAppendingString:@”/fichier-a-downloader.txt]];
[textView performSelectorOnMainThread:@selector(setText:)with Object:@“waitUntilDone:是];
[textView performSelectorOnMainThread:@selector(setText:)with object:[FoctionUtile concatener:@“Sommaire du download pour le circuit—“chaine2:nomcuit chaine3:@”“chaine4:@”\n“]waituntldone:YES];
[textView performSelectorOnMainThread:@selector(setText:)with Object:[FoctionUtile concatener:textView.text chaine2:@“Nombre de fichierádownloader=>”chaine3:[NSString stringWithFormat:@“%d”,[listeFichier count]]chaine4:@“\n”]Waituntldone:YES];
如果([listfichier count]>0)
{
if([OperationFicHierDossier SupplierDossierDossierFicier:ChemindossiersUriod]| |![OperationFicHierDossier验证档案存在:ChemindossierUriod]){
dossierExiste=[操作FICHIERDOSIER CRIERDOSIER:cheminDossierSurIpod];
}
如果(档案列表)
{
[textView performSelectorOnMainThread:@selector(setText:)with Object:[FonctionUtile concatener:textView.text chaine2:[FonctionUtile padderChaine:@“Fichiersádownloader”:27:@“”:TRUE]chaine3:@“下载成功”chaine4:@“\n”]Waituntldone:YES];
y=70;
对于(i=0;i<[listfichier count];i++)
{
nomFichier=[[listfichier objectAtIndex:i]retain];
if([自电信计费器编号:nomFichier:[功能用户编号:档案网络链接2:@”/“链接3:nomFichier链接4:@”“]:cheminDossierSurIpod:TRUE])
{
回复=@“Oui”;
}
其他的
{
回复=@“非”;
}
[textView performSelectorOnMainThread:@selector(setText:)with Object:[FonctionUtile concatener:textView.text chaine2:[FonctionUtile padderChaine:nomFichier:27:@”“:TRUE]chaine3:Response chaine4:@“\n”]waitUntilDone:YES];
y=y+20;
}
}
}
[textView performSelectorOnMainThread:@selector(setText:)with Object:[FoctionUtile concatener:textView.text chaine2:@“Fin du download pour-le circuit-”chaine3:nomCircuit chaine4:@“]waitUntilDone:YES];
[池释放];
}

此函数由performSelectorInBackground调用。

拥有
NSAutoreleasePool
是正确的。错误消息似乎表明您正在从后台线程操作UI元素(可能是
UIWebView
)。正如错误消息所说,这不是一件好事™.

您收到的消息未与使用NSAutoreleasePool连接。看起来您正在从辅助线程更新UI元素,但它应该只在主线程上执行;但这样做是不对的?因为如果我不放这一行,控制台中就没有消息。您有一个名为
padderChaine::
concatener:chaine2:chaine3:chaine4:
?哎哟!不要那样做!交错参数是由每个参数冒号前面的选择器部分来描述的。我的英语不是很好,我不理解你的句子,你能用其他的话解释一下吗。命名方法被认为是不好的形式
-method::
。在冒号之间应该有描述性术语,以使方法更具可读性。看看苹果如何在Cocoa API中命名方法,作为您应该如何设计代码的示例。为什么这不是一件好事?这一行在一个循环中[textView PerformSelector OnMainThread:@selector(setText:)with Object:@“test”waitUntilDone:是]我把它放在一个辅助线程中,因为如果它在主线程中,textView只会在函数末尾刷新。@alex这是在主线程上操作的,而不是在后台线程上操作的。错误消息似乎表明正在发生其他事情。也许你可以把身体或你的方法放在这个问题上?我把我的功能放在这个问题上@alex-除非某个自定义类中出现问题,否则我在新代码中看到的唯一问题就是
textView.text
,在这里,您可以从后台线程访问textView上的属性。这可能是触发警告的原因。