//大图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. 【NOIP2016】蚯蚓(队列,单调性)

    题目不再重复叙述 请参考: 洛谷 CJOJ 题解 先来说说非完美解法,也是我去年考场上的做法 考虑一下每一只蚯蚓增加的长度, 这个值并不需要每一次依次增加, 用一个变量维护即可,每次取出蚯蚓就加上这个 ...

  2. Bzoj4805: 欧拉函数求和

    好久没写杜教筛了 练练手AC量刷起 # include <bits/stdc++.h> # define RG register # define IL inline # define F ...

  3. Office 365 Connectors 的使用与自定义开发

    前言 我相信很多人都看过<三国演义>,里面有很多引人入胜的故事和栩栩如生的人物,对我而言,曹操手下的一员猛将典韦实在让我印象深刻.例如,书中有一段描写典韦的作战经历: 时西面又急,韦进当之 ...

  4. jxl 导出数据到excel

    优点: Jxl对中文支持非常好,操作简单,方法看名知意. Jxl是纯javaAPI,在跨平台上表现的非常完美,代码可以再windows或者Linux上运行而无需重新编写 支持Excel 95-2000 ...

  5. MySQL配置文件

    [mysqld]datadir=/usr/local//mysql/data    #数据存放位置socket=/var/lib/mysql/mysql.sockuser=mysqllower_cas ...

  6. 云计算之路-阿里云上:博客web服务器轮番CPU 100%

    今天下午14:30左右开始,不知道怎么回事,博客站点负载均衡中的web服务器轮番CPU 100%.平时访问高峰5台服务器就能稳稳支撑,而今天发现CPU出现100%问题后就开始加服务器,结果到目前加到了 ...

  7. java多线程的常见例子

    收藏 http://blog.csdn.net/wenzhi20102321/article/details/52524545

  8. js改变盒子大小(上下左右)分析

    js改变盒子大小 知识点 三个mouse事件:mousedown mousemove mouseup css的定位和cursor 思路 先解决单边问题识别范围,得到所选区域 event. 根据距离,判 ...

  9. c# redis 操作类库推荐:StackExchange.Redis.Extensions

    StackExchange是一个优秀的c# redis客户端,但是存在操作略为繁琐的弊端,为了简化操作,使用 StackExchange.Redis.Extensions成为了一个非常值得推荐的选择. ...

  10. Bond UVA - 11354(LCA应用题)

    Once again, James Bond is on his way to saving the world. Bond's latest mission requires him to trav ...