CoreImage memory build up on real device but not on simulator

I'm trying to benchmark a Core Image filter chains memory footprint and notice a weird quirk in instruments.

On a real device, even with a simple Core Image chain, the memory balloons each time I ran the filter. See attached screen shots.

Running on iPhone 17 Pro:

Running on simulator (M2 Macbook Pro)

As you can see there's a huge build up of 4MB "VM: IOSurface" memory on the real device, but the simulator seems to clean it up correctly.

Here's my basic code:

func processImage() {
        guard let inputImage = ContentViewModel.loadImageFromBundle(name: "kitty.HEIC") else {
            print("Failed to load sample_image from bundle")
            return
        }
        
        var outputImage = inputImage
        
        outputImage = outputImage.applyingFilter("CIBloom", parameters: [
            kCIInputRadiusKey: 20,
            kCIInputIntensityKey: 0.8
        ])
        
        DispatchQueue.global(qos: .userInitiated).async {
            
            let data = self.context.jpegRepresentation(of: outputImage, colorSpace: CGColorSpace(name: CGColorSpace.sRGB)!)
            
            if let data = data, let uiImage = UIImage(data: data) {
                DispatchQueue.main.async {
                    self.displayImage = Image(uiImage: uiImage)
                }
            }
            
        }
    }

Why is this happening? Seems like a bug to me or I need to release an object. At the very least makes it challenging to measure memory usage.

Any help is greatly appreciated. Alex

Did you always process the same image? How is your CIContext set up? Do you maybe have a small sample project we can use to test this? Thanks!

CoreImage memory build up on real device but not on simulator
 
 
Q