2010-12-11 83 views
0


ceci est mon extrait:Comment puis-je résoudre cette fuite de mémoire?

- (id) initWithFrame:(CGRect)frame andConfig:(PGParams*) params 
{ 

for (int i=0; i<[conf.map count]; i++) 
    [conf.map replaceObjectAtIndex:i withObject: 
     [[NSString alloc] initWithFormat:@"%@&sito=%@", 
     [conf.map objectAtIndex:i], [params sito]]]; 

for (int i=0; i<[conf.orto count]; i++) 
    [conf.orto replaceObjectAtIndex:i withObject: 
     [[NSString alloc] initWithFormat:@"%@&sito=%@", 
     [conf.orto objectAtIndex:i], [params sito]]]; 

for (int i=0; i<[conf.mix count]; i++) 
    [conf.mix replaceObjectAtIndex:i withObject: 
     [[NSString alloc] initWithFormat:@"%@&sito=%@", 
     [conf.mix objectAtIndex:i], [params sito]]]; 

} 

ce code avec Compiler RUN_CLANG_STATIC_ANALYZER Option (Propriété d'> Construire Options-> Exécuter l'analyseur statique), il me montre une fuite sur [[NSString alloc] ....

RUN_CLANG_STATIC_ANALYZER

L'activation de ce paramètre entraîne Xcode pour exécuter l'outil d'analyse statique Clang sur les fichiers source de qualification. Cet outil prend actuellement en charge les fichiers C et Objective-C. [RUN_CLANG_STATIC_ANALYZER]


Comment puis-je résoudre?

merci à l'avance,
allberto

Répondre

3

droit. Vous allouez un objet que vous possédez (car vous avez appelé +alloc), mais vous ne le libérez jamais.

Vous pouvez remplacer toutes les instances de [[NSString alloc] initWithFormat:...] par [NSString stringWithFormat:...] pour réparer la fuite.

+0

à droite! merci, maintenant est fixé! – elp