problème de mémoire étrange
-
25-09-2019 - |
Question
À un certain moment, j'allouent un élément NSMutableData comme ceci:
NSMutableData* data=[[NSMutableData alloc] initWithLength:0];
Plus tard, je fais:
NSString *dataAsStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ;
completeCommand = [NSString stringWithFormat:@"%@%@",
incompleteMessage,
[dataAsStr substringWithRange:NSMakeRange(startIndex, i-startIndex)]];
[incompleteMessage release];
incompleteMessage = nil;
[dataAsStr release];
Et enfin j'appelle:
[data release]; //Here I get a BAD_ACCESS error since data gets a release count of -1
Maintenant, conformément aux instruments (allocations avec support zombie), la première ligne du deuxième bloc NSString * dataAsString = ... appelle [sortie de données]
Où est-ce que cela se produise?
La solution
Le mystère est résolu .. Son une méthode assez grande, donc je ne savais pas que [communiqué de données]; était dans une boucle et son malloc n'était pas. C'était à l'origine du zombie.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow