Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Memory Usage increasing alot when using GetFrameBufferAsync #205

Open
CodingWithGelos opened this issue Dec 11, 2020 · 3 comments
Open

Memory Usage increasing alot when using GetFrameBufferAsync #205

CodingWithGelos opened this issue Dec 11, 2020 · 3 comments

Comments

@CodingWithGelos
Copy link

CodingWithGelos commented Dec 11, 2020

Hi, so i've been testing and I realize that using GetFrameBufferAsync causes my program's memory to increase alot, and eventually run out of memory. Is there a way to solve this? Or am I using the function wrongly?

return adbClient.GetFrameBufferAsync(device, CancellationToken.None).Result as Bitmap;

I'm using this function to grab screenshots from my android emulator.

@HughJeffner
Copy link

HughJeffner commented Aug 13, 2021

Same here using version 2.3.23. It didn't exhibit this behavior when using version 2.2.35

I'm using it like this:

using (var framebuffer = await this.adbClient.GetFrameBufferAsync(this.Device, cancellationToken))
{
    using (Bitmap b = new Bitmap(framebuffer))
    {
        foreach (var item in coords)
        {
            ret.Add(b.GetPixel(item.Item1, item.Item2));
        }
    }
}

Memory use over time:
image

I didn't let this session run as long, but it just keeps growing and growing despite the GC's. Previously, the app consumed about 50-60MB. The only change I made was updating the NuGet package to the current newest version.

@HughJeffner
Copy link

Some more info since I had time

  1. I'm targeting .NET Framework 4.6.2
  2. If I use CreateRefreshableFramebuffer to get a single FrameBuffer instance and hold on to it to get screenshots the memory leak doesn't happen. (I call this method many times)
if (frameBuffer == null) frameBuffer = adbClient.CreateRefreshableFramebuffer(this.Device);

await frameBuffer.RefreshAsync(cancellationToken);

using (var image = frameBuffer.ToImage())
{
    using (Bitmap b = new Bitmap(image))
    {

        foreach (var item in coords)
        {
            ret.Add(b.GetPixel(item.Item1, item.Item2));
        }

    }
}

Maybe related to this removal of compile directives?
fe0a565#diff-f39a5f810244fb6a97de3b5c9e830faa791c056add9f5c78e04bf7b054eea64bL119

@seltix5
Copy link

seltix5 commented Dec 15, 2022

hello,
I was browsing this library because of another problem with screenshots and I saw this issue. I know this is an old issue but this may help others since it may not be fixed. I posted my fix for the memory leak of GetFrameBufferAsync here : SharpAdb/AdvancedSharpAdbClient#3 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants