Skip to content

When using CoreGraphics to draw in background thread memory usage of the app is getting very high until the App eventually crashes #115

@customer-glassboxdigital

Description

If I call the following function (drawBlackRect) from AppDelegate didFinishLaunchingWithOptions and play with the pdf (zoom in/out, swipe to next page etc ...), the memory usage of the app is getting very high until the app eventually crashes. I also added the same code translated to objective c to PhotoScroller, and the issue doesn't reproduce.

func drawBlackRect() {
DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + .milliseconds(500)) {

               let width = 375;
               let height = 667;
               var imageBuffer = [UInt8](repeating: 0, count: width*height*4)
               imageBuffer.withUnsafeMutableBytes { pointer in
                   
                   guard let context = CGContext(data: pointer.baseAddress,
                                               width: width,
                                               height: height,
                                               bitsPerComponent: 8,
                                               bytesPerRow: width*4,
                                               space: self.colorSpace,
                                               bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue).rawValue)
                   else {
                       return
                   }
                   // Draw a black background
                   let layer = CALayer()
                   layer.backgroundColor = UIColor.black.cgColor;
                   layer.frame = CGRect(x: 0, y: 0, width: 375, height: 667)
                   layer.render(in: context)
                   let _ = context.makeImage();
               
               }
           }
           self.drawBlackRect()
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions