Ich habe ein Speicherleckproblem von einer sehr einfachen Funktion. Hier ist mein Code:UIImage setImage: Ursache Speicherverlust
-(void) drawPuzzle
{
gameView.image=nil;
UIGraphicsBeginImageContext(gameView.frame.size);
[gameView.image drawInRect:CGRectMake(0,
0,
gameView.frame.size.width,
gameView.frame.size.height)];
CGContextRef con=UIGraphicsGetCurrentContext();
CGContextMoveToPoint(con, 20,0);
CGContextAddLineToPoint(con,20, gameView.frame.size.height);
CGContextStrokePath(con);
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[gameView setImage:newImage];
}
Die Instrumente berichten wie folgt:
Event Type RefCt Responsible Caller
Malloc 1 +[UIImage imageWithCGImage: scale: orientation:]
Autorelease +[UIImage imageWithCGImage: scale: orientation:]
Retain 2 -[UIImageView setImage:]
Release 1 -[NSAutoreleasePool drain]
entbinden Sie gameView.image? (Angenommen, es wird von setImage beibehalten) – giorashc
Wie? [gameView.image release] oder gameView.image = nil? Ich weiß nicht, warum ich [gameView.image release] brauche, aber ich habe gameView.image = nil vor [gameView release]. – Lynn
[gameView.image release]; – Lynn