alex
alex

Reputation: 879

secondary thread with nsautoreleasepool

I call a function with performSelectorInBackground, and in this function, I declare

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

at the beginning

[pool release];         

at the end

But in the console, I have this message:

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.

Why? Because if I don't put a nsautoreasepool in my function I have a lot of message like this:

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

thanks for your help

-(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];
}

and this function is call by performSelectorInBackground.

Upvotes: 0

Views: 1100

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

Having the NSAutoreleasePool is correct. The error message just seems to indicate that you're manipulating a UI element (a UIWebView, perhaps) from the background thread. As the error message says, this is not A Good Thing™.

Upvotes: 1

Related Questions