Product -> Analyse – 1 Answers" /> Product -> Analyse – 1 Answers" />

Autogestión / liberación de objetos informados como "Posible fuga de objeto" en Xcode -> Producto -> Analizar

The Analyse feature of Xcode 4 is really great. The only problem is it thinks that objects that you initialise that are supposed to release themselves are reported as memory leaks.. ie how do you prevent it thinking this is a memory leak?

@interface BackgroundTaskThing

+ doBackgroundTask: (NSString*) something {
    BackgroundTaskThing* b = [[BackgroundTaskThing alloc] init];
    [b setSomething: something];
    [b runTask];


- (void)taskComplete {
    [self release];


preguntado el 28 de agosto de 11 a las 02:08

Bear in mind that self-releasing objects like this will break under ARC, should you ever decide to migrate your code. -

1 Respuestas

Desde aquí, section Controlling 'Static Analyzer Diagnostics':

#ifndef __clang_analyzer__
// Code not to be analyzed

(not that i encourage this, but it is one way to disable it)

Respondido el 01 de Septiembre de 11 a las 23:09

That is one way. However, an argument could be made that the object should generally not be releasing itself. If it is in a processing queue somewhere, that queue (or block in the queue) should hold the reference. It is, in general, a tricky problem. - bbum

It was a tough decision at the time related to if it should be done this way, however I remember reading some apple documentation at the time suggesting this was an ok practice under some circumstances. - arrendajo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.