0

Memory keeps building up and not releasing with GPUImage. If I change the filter on a UIImage, the old filter memory is never released

My code:

Have a UIImageView as a class property:

@property(nonatomic,strong) UIImageView *capturedImageView;

I apply the filter like so

GPUImageFilter filter = [[GPUImageGrayscaleFilter alloc] init];
UIImage *filteredImage = [filter imageByFilteringImage:[UIImage imageWithCGImage:myImage.CGImage]];
[filter removeAllTargets];
[filter endProcessing];

I then set the imageView.image property to the filtered image

self.capturedImageView.image = filteredImage;

Now at any time I might change the filter (based on what a user selects (ie an instagram like filter list)). When I do change the filter I just use the code above (but alloc a different filter)

I don't understand why memory keeps building up? I tried setting my imageview.image property to nil and GPIFilter to nil but that does nothing

MobileMon
  • 8,341
  • 5
  • 56
  • 75
  • If you are not using ARC, trying releasing the filtered image, and then setting the filtered image to something else. – SierraMike Dec 09 '14 at 02:22
  • I'm using ARC, tried setting filter to nil with no luck – MobileMon Dec 09 '14 at 02:26
  • Most likely its because you are constantly creating new filters. Have you tried creating them only once and then passing around the filters pointers on demand instead of creating a filter each time? – SierraMike Dec 09 '14 at 02:35
  • Yeah I tried that too. Not sure why that would help. Would also be inefficient to create a bunch of filters which may or may not get used but that regardless of the point. That tactic doesn't work :( – MobileMon Dec 09 '14 at 02:46
  • Its helpful because you will only have an instance of the gray filter compared to multiple instances of a gray filter if the user constantly switches between a gray filter and a non-gray filter. – SierraMike Dec 09 '14 at 02:48
  • Since the instance only lives locally inside a method it should release itself right? Its not a class property – MobileMon Dec 09 '14 at 02:55
  • Are you experiencing this on device? – Andrea Dec 09 '14 at 08:19
  • @Andrea yes on both the device and simulator – MobileMon Dec 09 '14 at 19:45
  • What is the class of `myImage` in your example ? This [thread](http://stackoverflow.com/questions/23656934/imagewithcgimage-leaks-according-to-instrument) states that `imageWithCGImage` might be linked to your memory leak. What does instrument shows ? – lazi74 Dec 10 '14 at 22:34
  • I'm seeing this same behavior when using Swift as well as using Objective-C. – djunod May 12 '15 at 22:32

0 Answers0