Memory Usage increasing alot when using GetFrameBufferAsync
CodingWithGelos opened this issue · 3 comments
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.
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));
}
}
}
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.
Some more info since I had time
- I'm targeting .NET Framework 4.6.2
- If I use
CreateRefreshableFramebuffer
to get a singleFrameBuffer
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
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)