다른 .m 파일의 이미지를 처리하려고합니다. 현재 다음은 내 코드입니다. 두 개의 UIImages를 저장하고 두 개를 처리하는 전역 NSMutableArray가 있습니다. 사용자가 버튼을 클릭 할 때마다 두 개의 그림을 전역 배열에 저장하여 처리 한 다음 요소를 제거합니다. ARC를 사용 중이므로 아무런 발표도 필요하지 않습니다.ARC GPUImage를 사용한 메모리 누수
@implementation
NSMutableArray * imagesArray;
ImageProcessor *imageProcessor;
...
- (void)viewDidLoad {
imagesArray = [[NSMutableArray alloc] init];
imageProcessor = [[ImageProcessor alloc] init];
//some other code
}
-(UIImage*)processImages{//process images using GPUImage
UIImage *firstImg = [[imagesArray objectAtIndex:1] copy];
UIImage *secImg = [[imagesArray objectAtIndex:0] copy];
UIImage *processedImage = [imageProcessor flashSubtract:firstImg : secImg];
UIImage *dividedImage = [imageProcessor referenceDivide:processedImage];
// [self uploadDropbox:UIImagePNGRepresentation(processedImage) : @"Output.png"];//try to save tiff files
//using ARC, no explicit memory releasing required
NSLog(@"image processed!");
[imagesArray removeAllObjects];
return dividedImage;
}
ImageProcessor.m :
#import "ImageProcessor.h"
@interface ImageProcessor()
@end
@implementation ImageProcessor
GPUImageSubtractBlendFilter *subFilter;
GPUImageDivideBlendFilter* divFilter;
-(id)init {
self = [super init];
//initialize filters
subFilter = [[GPUImageSubtractBlendFilter alloc] init];
divFilter = [[GPUImageDivideBlendFilter alloc] init];
return self;
}
-(UIImage*)flashSubtract:(UIImage*) image1 : (UIImage*) image2{
UIImage *processedImage;
// @autoreleasepool {
//CAUSING MEMORY ISSUE
GPUImagePicture *img1 = [[GPUImagePicture alloc] initWithImage:image1];//image with flash
GPUImagePicture *img2 = [[GPUImagePicture alloc] initWithImage:image2];//image without flash
//MEMORY ISSUE END
[img1 addTarget:subFilter];
[img2 addTarget:subFilter];
[img1 processImage];
[img2 processImage];
[subFilter useNextFrameForImageCapture];
processedImage = [subFilter imageFromCurrentFramebuffer];
// }
//consider modifications to filter possibly?
return processedImage;
}
@end
난 후 [imageProcessor가 flashSubtract]가 메모리 할당을 해제하지 않는 메모리 누수 문제를 얻고있다. 메모리 사용량이 계속 증가하고 약 30 장의 사진 이후 앱이 다운됩니다. 제가 잘못했는지 알려주세요. 어떤 도움을 주시면 감사하겠습니다. 문제를 식별하는 데 유용 할 수 있습니다,
죄송합니다. 저는 __weak으로 테스트를 진행 했었습니다. 객관적으로 새로운 것 때문에 옵션을 다 써 버리고있었습니다. 네, 그걸로 뭔가 할 수있는 nsmutable 배열을 사용하는 것 같아 –