在arc模式下 CGImage 释放问题
//大图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 = [UIImage imageWithCGImage: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 = [UIImage imageWithCGImage: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模式下的内存泄露问题
ARC模式下的内存泄露问题 iOS提供的ARC 功能很大程度上简化了编程,让内存管理变得越来越简单,但是ARC并不是说不会发生内存泄露,使用不当照样会发生. 以下列举两种内存泄露情况: 死循环造成的内 ...
- xcode4.3.2 arc模式下导入非arc的文件 转
在arc模式下,我们经常会用到非arc的类库,此时我们可以在Compile Sources下对该文件进行编辑加入 -fno-objc-arc 如图中所示,就可以使用非arc的类库了 转:htt ...
- 1.ARC模式下如何兼容非ARC的类
ARC模式下如何兼容非ARC的类 :转变为ARC的, -f-objc-arc 非ARC模式下如何兼容ARC的类 :转变为非ARC -fno-objc-arc
- ARC模式下的单例写法
// 单例 + (id)sharedInstance { __strong static id sharedObject = nil; static dispatch_once_t onceToken ...
- ARC模式下获取retainCount的方法
_objc_rootRetainCount(obj)可以获取obj的retainCount,不过不清楚是不是私有api,因此建议调试时使用.
- ARC模式下delloc()注意事项
1.ARC模式下delloc()调用触发时机是对象被销毁,如self.属性=nil 2.ARC模式下delloc()里面不需要手动调用[super dealloc]; 因为系统已经自动调用,多此一举的 ...
- 0c-42-ARC模式下如何兼容非ARC的类
1.ARC模式下如何兼容非ARC的类 让程序兼容ARC和非ARC部分.转变为非ARC -fno-objc-arc 2.将MRC转换为ARC ARC也需要考虑循环引用问题:一端用strong,一端用we ...
- ASIHTTPRequest 在release(打包)模式下数据获取或post失败问题
ASIHTTPRequest 在relase模式下失效 表现为,调用网络请求后没有任何反应 原因之一: ARC模式下,在ASIHTTPRequest 前面会加上__weak来解决循环应用,这个__we ...
- Apache Spark源码走读之19 -- standalone cluster模式下资源的申请与释放
欢迎转载,转载请注明出处,徽沪一郎. 概要 本文主要讲述在standalone cluster部署模式下,Spark Application在整个运行期间,资源(主要是cpu core和内存)的申请与 ...
随机推荐
- Android集成百度地图详细步骤和错误问题
先看要实现的效果 第一步, 下载SDK,基础配置,百度开发文档很详细,直接附上链接http://lbsyun.baidu.com/index.php?title=androidsdk/guide/cr ...
- [HNOI2013]游走
题面在这里 题意 从1号点开始等概率选择路径并加上边权,直到到达n号点结束,要求将m条边赋权值1-m使得期望最小 sol 续上文 zsy ycb orz 简单的贪心:求出每条边的期望经过次数,sort ...
- nginx学习之rewrite
rewrite 语法学习 什么是rewrite nginx的rewrite主要功是实现URL地址重写.nginx的rewrite规则需要PCRE的支持,既可以通过Perl兼容正则表达式进行规则匹配.n ...
- 19.JavaScript
简介 JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型 1.注释 单行 // 多行 /* */ 2.引用方式 <head> <meta c ...
- 【Unity与23种设计模式】备忘录模式(Memento)
GoF中定义: "在不违反封装的原则下,获取一个对象的内部状态并保留在外部,让对象可以在日后恢复到原先保留时的状态." 对于一些需要存储的数据,比如历史最高分 当与得分减分系统写入 ...
- 基于双向BiLstm神经网络的中文分词详解及源码
基于双向BiLstm神经网络的中文分词详解及源码 基于双向BiLstm神经网络的中文分词详解及源码 1 标注序列 2 训练网络 3 Viterbi算法求解最优路径 4 keras代码讲解 最后 源代码 ...
- 设计模式——装饰器模式(C++实现)
#include <iostream> #include <string> using namespace std; class Component { public: ; } ...
- jni 类初始化失败(nested exception is java.lang.NoClassDefFoundError)
nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.netease.facedetec ...
- Git -- 分支与合并 (命令行+可视化工具p4merge)
基本命令 把所有的变化都放在master分支并不是最好的做法. 建议的做法是把变化放在分支里面. 至少应该准备一个feature分支之类的, 把变化都隔离开来, 然后等到所有的功能都稳定之后再合并到m ...
- 二分查找(Java实现)
二分查找:递归实现 public class BinarySearch { /** * @param arr 代查找的数组,需要有序 * @param left 查找区间的左界限 * @param r ...