//大图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 释放问题的更多相关文章

  1. ARC模式下的内存泄露问题

    ARC模式下的内存泄露问题 iOS提供的ARC 功能很大程度上简化了编程,让内存管理变得越来越简单,但是ARC并不是说不会发生内存泄露,使用不当照样会发生. 以下列举两种内存泄露情况: 死循环造成的内 ...

  2. xcode4.3.2 arc模式下导入非arc的文件 转

    在arc模式下,我们经常会用到非arc的类库,此时我们可以在Compile Sources下对该文件进行编辑加入 -fno-objc-arc   如图中所示,就可以使用非arc的类库了   转:htt ...

  3. 1.ARC模式下如何兼容非ARC的类

    ARC模式下如何兼容非ARC的类 :转变为ARC的, -f-objc-arc 非ARC模式下如何兼容ARC的类 :转变为非ARC -fno-objc-arc

  4. ARC模式下的单例写法

    // 单例 + (id)sharedInstance { __strong static id sharedObject = nil; static dispatch_once_t onceToken ...

  5. ARC模式下获取retainCount的方法

    _objc_rootRetainCount(obj)可以获取obj的retainCount,不过不清楚是不是私有api,因此建议调试时使用.

  6. ARC模式下delloc()注意事项

    1.ARC模式下delloc()调用触发时机是对象被销毁,如self.属性=nil 2.ARC模式下delloc()里面不需要手动调用[super dealloc]; 因为系统已经自动调用,多此一举的 ...

  7. 0c-42-ARC模式下如何兼容非ARC的类

    1.ARC模式下如何兼容非ARC的类 让程序兼容ARC和非ARC部分.转变为非ARC -fno-objc-arc 2.将MRC转换为ARC ARC也需要考虑循环引用问题:一端用strong,一端用we ...

  8. ASIHTTPRequest 在release(打包)模式下数据获取或post失败问题

    ASIHTTPRequest 在relase模式下失效 表现为,调用网络请求后没有任何反应 原因之一: ARC模式下,在ASIHTTPRequest 前面会加上__weak来解决循环应用,这个__we ...

  9. Apache Spark源码走读之19 -- standalone cluster模式下资源的申请与释放

    欢迎转载,转载请注明出处,徽沪一郎. 概要 本文主要讲述在standalone cluster部署模式下,Spark Application在整个运行期间,资源(主要是cpu core和内存)的申请与 ...

随机推荐

  1. xshell无法登录阿里云服务器

    1. 现象 a. 使用xshell无法登录服务器 b. 查看sshd服务 c. 不同公网ip的电脑正常登陆 2. 解决方案 a. 不同公网ip可以登录,断定是ip被黑名单,联系阿里云服务,把公网ip加 ...

  2. 第三篇:数据可视化 - ggplot2

    前言 R语言的强大之处在于统计和作图.其中统计部分的内容很多很强大,因此会在以后的实例中逐步介绍:而作图部分的套路相对来说是比较固定的,现在可以先对它做一个总体的认识. 在上一篇文章中,介绍了使用gr ...

  3. 数列分块总结——题目总版(hzwer分块九题及其他题目)(分块)

    闲话 莫队算法似乎还是需要一点分块思想的......于是我就先来搞分块啦! 膜拜hzwer学长神犇%%%Orz 这九道题,每一道都堪称经典,强力打Call!点这里进入 算法简述 每一次考试被炸得体无完 ...

  4. [POI2014]HOT-Hotels

    题目描述 There are towns in Byteotia, connected with only roads. Each road directly links two towns. All ...

  5. createjs绘制扇形的方法

    扇形由三段线条组成,两条直线和一条弧线,直线可以用createjs中的lineTo函数画出,弧线用Graphics.arc函数来画. 一.关于createjs中的Graphics.Arc API Gr ...

  6. Python多线程爬虫与多种数据存储方式实现(Python爬虫实战2)

    1. 多进程爬虫 对于数据量较大的爬虫,对数据的处理要求较高时,可以采用python多进程或多线程的机制完成,多进程是指分配多个CPU处理程序,同一时刻只有一个CPU在工作,多线程是指进程内部有多个类 ...

  7. k60引脚图

    /*! 枚举管脚编号 */ typedef enum { /* PTA端口 */ //0~31 PTA0, PTA1, PTA2, PTA3, PTA4, PTA5, PTA6, PTA7, PTA8 ...

  8. JavaIO 总结

    另外参考文章:http://www.ibm.com/developerworks/cn/java/j-lo-javaio/ 一. File类 file.createNewFile();file.del ...

  9. prompt 方法显示输入对话框

    prompt 方法显示输入对话框 原理: prompt() 方法用于与用户交互,提示用户输入信息的对话框. prompt(str1,str2);此方法包含两个属性: str1:用于提示用户输入的信息. ...

  10. segment fault异常及常见定位手段

    问题背景 最近boot中遇到个用户态程序的segment fault异常,除了一句"Segment fault"打印外无其他任何打印.该问题复现概率较低,定位起来比较棘手.我们的b ...