分享

主题 : Received memory warning

 没原创_去搜索 2015-08-01
  • 技术问题发到问答:我知道,我仍旧要在论坛继续发布问题
大大们,我用ALAssetsLibrary把照片库里的照片copy到app的Documents下面,总是到一百多张后就出现内存警告,然后crash,请帮忙看看是哪里的问题,不胜感激!!!
dispatch_async(dispatch_get_global_queue(00), ^{

NSAutoreleasePool *pool = [[NSAutoreleasePool allocinit];
           [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:ALAssetPropertyTypeisEqualToString: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 defaultManagerfileExistsAtPath:fullPath]){

                            [[NSFileManager defaultManagercreateFileAtPath: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 allocinit];
           [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                                  usingBlock:libraryGroupsEnumeration
                                failureBlock:failureblock];
           [library release];

       });



奋斗+努力=???
级别: 侠客
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的内存地址,你比较一下两次的内存地址。你就明白问题的原因所在了 
级别: 精灵王
    
状态: 未签到 - [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
求解惑 
奋斗+努力=???
级别: 精灵王
    
状态: 未签到 - [4天]
UID: 42403
精华: 0 
发帖: 900
可可豆: 4062 CB
威望: 4390 点
在线时间: 1204(时)
注册时间: 2010-12-13
最后登录: 2015-07-31
3 楼: 发表于: 2013-01-29 17:35   发自: Web Page
回 1楼(siam) 的帖子
我原来是这样的UIImage *image = [[UIImage alloc]initWithCGImage:iref];
不过这样到80张图片就Received memory warning.然后crash
求解惑 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多