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