1
這段代碼似乎存在內存泄漏,但我找不到它。我究竟做錯了什麼?具體而言,第1行和第2行增加了應用程序的內存使用情況,並且只有第一行的內存在上下文結束時消失。UIGraphics內存泄漏
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
編輯1: 完整方法如下代碼:
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(0, 0, self.view.frame.size.width + 16 - ((int)self.view.frame.size.width % 16), self.view.frame.size.height + 16 - ((int)self.view.frame.size.height % 16))]; // If image width and height is not a multiple of 16, the video becomes distorted when written to a file
imageView.contentMode = UIViewContentModeScaleToFill;
[imageView addSubview:[[UIImageView alloc] initWithImage:[ViewController makeRedCircle]]];
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
是什麼讓你覺得有泄漏? – matt
@matt它每次運行時都會永久性地向內存中添加幾兆字節。我使用Xcode在iPhone 6上測試了應用程序。 – mntruell
你使用過儀器嗎? - 什麼是'圖像'?你以後在做什麼?換句話說,你可以給我代碼,我可以實際運行,以重現你的泄漏? – matt