在arc模式下 CGImage 释放问题
来源:互联网 发布:得力美工刀片价格 编辑:程序博客网 时间:2024/05/20 09:22
后来才发现 根本不是那么回事
//裁减图片
-(UIImage *)getImageFromImage:(UIImage *)i :(int)imagecount{
//大图bigImage
//定义myImageRect,截图的区域
if (imagecount >= 3) {
CGRect myImageRect;
if (i.size.width<= i.size.height) {
myImageRect = CGRectMake(0.0,150.0, i.size.width, i.size.width);
}
else
myImageRect = CGRectMake(0.0,150.0, i.size.height, i.size.height);
UIImage* bigImage= i;
CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width = 80;
size.height = 80;
UIGraphicsBeginImageContext(size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* smallImage = [UIImageimageWithCGImage:subImageRef];
CGImageRelease(subImageRef);
UIGraphicsEndImageContext();
return smallImage;
}
if (imagecount < 3) {
CGRect myImageRect;
if (i.size.width<= i.size.height) {
myImageRect = CGRectMake(0.0,150.0, i.size.width, i.size.width*2/3);
}
else
myImageRect = CGRectMake(0.0,150.0, i.size.height, i.size.height*2/3);
UIImage* bigImage= i;
CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width = 120;
size.height = 80;
UIGraphicsBeginImageContext(size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* smallImage = [UIImageimageWithCGImage:subImageRef]; //注意蓝色的部分
CGImageRelease(subImageRef);
return smallImage;
}
return nil;
}
像这样 裁剪图片 就会有内存泄漏
后来上 stackoverflow 查找 发现这样一段话
ARC does not manage C-types, of which CGImage may be considered. You must release the ref manually when you are finished with CGImageRelease(image);
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
CGImageRelease(subImageRef);
UIGraphicsEndImageContext();
也就是 在arc模式下 不是什么东西 都可以释放 例如 C-types的对象 都需要手动来进行释放- 在arc模式下 CGImage 释放问题
- 在arc模式下 CGImage 释放问题
- ARC模式下解决释放对象问题
- ARC模式下内存释放
- ARC模式如何释放
- IOS ARC模式下释放ViewController的内存
- UIImageView 的 UIImage 在 ARC 下释放内存
- arc下如何释放内存
- 非ARC下的内存释放
- ARC环境下,自动释放UIViewController...
- ARC下如何实现内存释放
- ARC下如何实现内存释放
- block在ARC和非ARC的内存释放
- iOS 在ARC模式下使用MRC的类
- iOS 在ARC模式下使用MRC的工程
- 关于WYPopoverController在ARC下的自动dismiss的问题
- 在ARC与非ARC下 iOS创建单例 遇到的问题
- ARC下属性对象实例对象内存释放时机
- Arcgis 10.2 中sde用oralc 做地理数据库。
- NGINX-based Media Streaming Server
- 语音识别系统之kaldi-----安装续
- 《黑马程序员》 字符流和字节流 -----第十八天
- 南阳理工OJ_猴子吃桃问题
- 在arc模式下 CGImage 释放问题
- gps hal用到的函数4--socketpair
- mac上传文件到aws ec2 instance
- this指针
- 指针和数组的学习
- socketpair的使用
- SQL锁
- fix协议介绍16-查询叮当(quote)
- C# GetManifestResourceStream获取资源为null