技术问题发到问答:我知道,我仍旧要在论坛继续发布问题
大大们,我用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
求解惑