打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
主题 : Received memory warning
技术问题发到问答:我知道,我仍旧要在论坛继续发布问题
大大们,我用ALAssetsLibrary把照片库里的照片copy到app的Documents下面,总是到一百多张后就出现内存警告,然后crash,请帮忙看看是哪里的问题,不胜感激!!!
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool release];
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
NSLog(@"error occour =%@", [myerror localizedDescription]);
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result!=NULL) {
//we can get all the things in the  defaultRepresentation  such as size info in UTI
}
//just fetching photos
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
//把image copy 到Documents/DMS/Photo文件夹下面
ALAssetRepresentation *rep = [result defaultRepresentation];
CGImageRef iref = [rep fullScreenImage];
NSString *tt = [rep filename];
if (iref) {
UIImage *image = [[UIImage alloc]init];
image  = [UIImage imageWithCGImage:iref];
NSData *imageData = [[NSData alloc]init];
imageData = UIImagePNGRepresentation(image);
if(image==nil){
NSLog(@"---------------------the imageData is nil");
}else{
NSString *fullPath = [pathPhoto stringByAppendingFormat:@"/%@.png",tt];
NSLog(@"fullPath================%@",fullPath);
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]){
[[NSFileManager defaultManager] createFileAtPath:fullPath contents:imageData attributes:nil];
NSLog(@"Creat image file fullPath================%@",fullPath);
}
}
[image release];
[imageData release];
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop){
if (group == nil)
{
return;
}
if (group!=nil) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
NSLog(@"finish--------------------------------------------");
//NSLog(@"photoUrlListArray=========%@",photoUrlListArray);
//[self performSelectorOnMainThread:@selector(exportPhotoUrls:) withObject:nil waitUntilDone:YES];
//[photoUrlListArray release];
return;
};
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
[library release];
});
奋斗+努力=???
引用
siam
级别: 侠客
UID: 107120
精华: 0
发帖: 122
可可豆: 549 CB
威望: 549 点
在线时间: 156(时)
注册时间: 2011-11-21
最后登录: 2015-03-27
发表于: 2013-01-29 16:29   发自: Web Page 
回 楼主(zuo198599999) 的帖子
你的代码居然没有crash,这才是让我很差异的地方,UIImage *image = [[UIImage alloc]init];
image  = [UIImage imageWithCGImage:iref];
就拿这两句来做例子说吧,你断点看一下,执行完第一句的时候,image的内存地址是多少,执行完第二句的时候,你再看一下image的内存地址,你比较一下两次的内存地址。你就明白问题的原因所在了
引用
zuo198599999
级别: 精灵王
 
 
 
状态: 未签到 - [4天]
UID: 42403
精华: 0
发帖: 900
可可豆: 4062 CB
威望: 4390 点
在线时间: 1204(时)
注册时间: 2010-12-13
最后登录: 2015-07-31
发表于: 2013-01-29 17:33   发自: Web Page 
我原来是这样的UIImage *image = [[UIImage alloc]initWithCGImage:iref];
不过这样到80张图片就Received memory warning.然后crash
求解惑
奋斗+努力=???
引用
zuo198599999
级别: 精灵王
 
 
 
状态: 未签到 - [4天]
UID: 42403
精华: 0
发帖: 900
可可豆: 4062 CB
威望: 4390 点
在线时间: 1204(时)
注册时间: 2010-12-13
最后登录: 2015-07-31
发表于: 2013-01-29 17:35   发自: Web Page 
回 1楼(siam) 的帖子
我原来是这样的UIImage *image = [[UIImage alloc]initWithCGImage:iref];
不过这样到80张图片就Received memory warning.然后crash
求解惑
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iOS中手把手教你集成地图(干货,百度地图为例)
IOS上传图片方法类
自定义UITabBarController
iphone开发常用代码
iphone开发常用代码(不断更新)
初学ios时候String的各种用法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服