screenshot icon indicating copy to clipboard operation
screenshot copied to clipboard

Image memory leak

Open kreativityapps opened this issue 3 years ago • 2 comments

Images are not released from memory.

For example taking several screenshots with captureFromWidget one after the other severely increases memory usage causing out of memory crash.

Solution: Please put image.dispose(); everywhere after byteData is extracted from image.

    final ByteData? byteData =
        await image.toByteData(format: ui.ImageByteFormat.png);
    
    image.dispose();    // needed to clean up memory
    image = null; // also important
    return byteData!.buffer.asUint8List();

kreativityapps avatar Oct 14 '21 15:10 kreativityapps

Hi @SachinGanesh,

I totally agree with @kreativityapps , there is memory leak, I faced some memory crashes too.

ibrahimdevs avatar Feb 08 '22 11:02 ibrahimdevs

I forked the project and fixed the problem, you can use it in your pubspec.yaml using:

screenshot:
  git:  https://github.com/rignaneseleo/screenshot.git

rignaneseleo avatar Jun 04 '22 12:06 rignaneseleo

Hi,

This has been fixed in latest versions. So closing this issue.

ritheshSalyan avatar Mar 15 '24 08:03 ritheshSalyan