I have implemented a group filter(GPUImageSepiaFilter, GPUImageExposureFilter, GPUImageSepiaFilter) for image editing. And I have one slider which is used to set custom "Exposure" (setExposure:) value. On the "didValueChanged" action method of slider, I am refreshing the image preview by calling "picture processImage". If I move the slider very fast or when repeatedly scrolling the slider, app crashes for sure due to memory issue.
- (void)viewDidLoad {
[super viewDidLoad];
self.originalPicture = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"IMG_0009.JPG"]];
self.filterGroup = [[GPUImageFilterGroup alloc] init];
GPUImageSepiaFilter *sepiaFilter = [[GPUImageSepiaFilter alloc] init];
[self.filterGroup addFilter:sepiaFilter];
GPUImageExposureFilter *pixellateFilter = [[GPUImageExposureFilter alloc] init];
[pixellateFilter setExposure:0.0f];
[self.filterGroup addFilter:pixellateFilter];
GPUImageSaturationFilter *saturation = [[GPUImageSaturationFilter alloc] init];
[self.filterGroup addFilter:saturation];
[sepiaFilter addTarget:pixellateFilter];
[pixellateFilter addTarget:saturation];
[self.filterGroup setInitialFilters:[NSArray arrayWithObjects:sepiaFilter, pixellateFilter,nil]];
[self.filterGroup setTerminalFilter:saturation];
[self.originalPicture addTarget:self.filterGroup];
GPUImageView *filterView = [[GPUImageView alloc] init];
self.view = filterView;
[self.filterGroup addTarget:filterView];
[self.originalPicture processImage];
[self.slider setMinimumTrackTintColor:[UIColor redColor]];
[self.slider setMaximumTrackTintColor:[UIColor greenColor]];
[self.view addSubview:self.slider];
}
- (IBAction)didChangeValue:(id)sender {
GPUImageExposureFilter *filter = (GPUImageExposureFilter *)[self.filterGroup filterAtIndex:1];
[filter setExposure:self.slider.value];
[self.originalPicture processImage];
}
Which is the best way to fix this? Or am I doing anything wrong?
Thanks,
Srinivas
Mine are just some advices about images and GPUImage:
height*width*n°channel*n°bit_for_each_channel
imageNamed
method caches images and even if they say that this memory will be evicted in memory pressure situation I never had the occasion to see that purge workingI'm not seeing anything wrong with your code in using GPUImage, but I would try to use smaller images (in pixel size) and first of all use allocations.