views:

68

answers:

1

Hi, 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.

+1  A: 

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™.

Dave DeLong
Why it's not a good thing? this line is in a loop[textView performSelectorOnMainThread:@selector(setText:) withObject:@"test" waitUntilDone:YES]I put this in a secondary thread because if it's in the main thread the textview only refresh at the end of the function.
alex
@alex that's manipulating on the main thread, not the background thread. The error message seems to indicate that something else is going on. Perhaps you could put the body or your method in the question?
Dave DeLong
I put my function in the question !
alex
@alex - Unless something happens within one of your custom classes, the only place I see a problem in your new code is `textView.text`, where you access a property on textView from the background thread. This may be what is triggering the warning.
Brad Larson