J'ai un problème étrange mais je suis tout à fait sûr, pour vous ce n'est pas. Si c'est le cas, aidez-moi s'il vous plaît ou expliquez. J'ai un tableau de 39 UIImages qui seront utilisés pour animer UIImageView. et après avoir joué l'animation, la mémoire ne se libère pas.Étrange problème de libération
- (void)viewDidLoad {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableArray* actionArray = [[NSMutableArray alloc]initWithCapacity:38];
for (int i=1; i<=39; i++) {
NSString* path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"bg_Level1_%.4d", i] ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
[path release];
[actionArray addObject:image];
[image release];
NSLog(@"path rc %d image %d", [path retainCount], [image retainCount]);
}
imageView.animationImages = actionArray;
imageView.animationDuration = 4.0;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
NSLog(@"RetainCount ActArr %d ImageView %d", [actionArray retainCount], [imageView retainCount]);
[actionArray release];
[pool drain];
[imageView release];
[self performSelector:@selector(playAnimation2) withObject:self afterDelay:5.0];
[super viewDidLoad];
}
-(void)playAnimation2{
if ([imageView isAnimating]) {
[imageView stopAnimating];
}
NSLog(@"RetainCount ImageView %d",[imageView retainCount]);
}
aucune fuite n'a été découverte mais la quantité de mémoire allouée est toujours de 24 mb.
ou ce n'est pas si nécessaire?
EDIT:
Désolé, ma faute. En raison de nombreux changements de mon code, je me suis perdu. Après analyse, je l'ai! Merci beaucoup!
Le code est:
- (void)viewDidLoad {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableArray* actionArray = [[NSMutableArray alloc]initWithCapacity:38];
for (int i=1; i<=39; i++) {
NSString* path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"bg_Level1_%.4d", i] ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
// [path release];
[actionArray addObject:image];
[image release];
NSLog(@"path rc %d image %d", [path retainCount], [image retainCount]);
}
imageView.animationImages = actionArray;
imageView.animationDuration = 4.0;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
NSLog(@"RetainCount ActArr %d ImageView %d", [actionArray retainCount], [imageView retainCount]);
[actionArray release];
[pool drain];
[self performSelector:@selector(playAnimation2) withObject:self afterDelay:5.0];
[super viewDidLoad];
}
-(void)playAnimation2{
if ([imageView isAnimating]) {
[imageView stopAnimating];
}
[imageView removeFromSuperview];
imageView.animationImages = nil;
NSLog(@"RetainCount ImageView %d",[imageView retainCount]);
}
Le problème était avec [path release];
-1 Parce que votre code ne fonctionne plus du tout. Il se bloque tout de suite parce que vous libérez * path *. Afficher le code réel. Edit: Ok, ça ne plante pas directement, mais ça * va * planter quand l'image sera libérée. – Eiko
Comment puis-je vous envoyer l'ensemble du projet? La chose la plus drôle est que rien ne se brise. – 0xDE4E15B
Bien sûr, il ne plante pas, car vos images ne sont pas libérées - d'où votre problème. – Eiko