Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.89k stars 10.48k forks source link

High RAM usage #4297

Open AkabaneErlangga opened 1 year ago

AkabaneErlangga commented 1 year ago

Environment

Describe the bug Memory usage jumped drastically a few moments after scrcpy connected to my phone. and the results of mirroring are very laggy and delayed. If I leave scrcpy running, my phone will start restarting because the memory is full.

image i have tried in my older phone (redmi 5A) and the result is same. i also tried to lower the bitrate and resolution, that memory usage does not increase as quickly as before but can still reach 90% in second

rom1v commented 12 months ago

Memory usage jumped drastically a few moments after scrcpy connected to my phone.

On the computer or the device? 91% of how much RAM?

and the results of mirroring are very laggy and delayed

If you record (scrcpy --record=file.mp4), is the recorded file laggy?

If I leave scrcpy running, my phone will start restarting because the memory is full.

OK so it seems it's on the device. The server on the device just uses the Android API MediaCodec, so if it takes memory it's probably a problem with the encoder implementation on your device.

You might try with another encoder.

AkabaneErlangga commented 12 months ago

my device's ram is 8GB. I try to record and everything went smoothly. I don't know why but after I run it using the default settings, everything runs normally now. this is different from yesterday. Yesterday I also used the default settings but the results were as I explained above.

thank you for your help. maybe if i have this issue again in the future, i will try to change the encoder

ning-wyze commented 7 months ago

just found similar issue from my devices

Environment

OS: Windows 10 scrcpy version: 2.3.1 installation method: windows release device model: Pixel 6
Android version: 14

image

rom1v commented 7 months ago

@ning-wyze Did you pass specific parameters to scrcpy? After how much time of scrcpy running did you observe this RAM usage?

ning-wyze commented 7 months ago

@ning-wyze Did you pass specific parameters to scrcpy? After how much time of scrcpy running did you observe this RAM usage?

Hi @rom1v

no params, I just starts directly from scrcpy.exe. Since I rarely shut down my device, it usually happens once every one or two days. Additionally, my machine has a total of 48 GB of memory.

rom1v commented 7 months ago

I thought I was able to reproduce it, because in my debug build I clearly saw the memory usage increase. But in fact it only happens with address sanitizer enabled (meson builddir -Db_sanitize=address). Without address sanitizer, I can't reproduce any obvious memory usage increase after mirroring a device (playing video and audio) on Linux.

I will try over a longer period of time, and I will try on Windows.

rom1v commented 7 months ago

To track down the issue, could you reproduce with scrcpy --no-audio?

ning-wyze commented 7 months ago

OK, I'll give it a try in the next couple of days.  Thank you !

rom1v commented 7 months ago

I played a video on the device and mirrored (without audio or with audio) for 10 minutes on Windows, I don't see any memory usage increase either. On your computer, does memory usage increase regularly (progressively)?

ning-wyze commented 7 months ago

I observed and didn't notice any noticeable increase in memory at a speed visible to the naked eye.

rom1v commented 7 months ago

OK, and when you start scrcpy, what is the memory usage?

ning-wyze commented 7 months ago

It's only about 70Mb image

ning-wyze commented 7 months ago

image image

AndroidDeveloperLB commented 5 months ago

I also have this issue. My command is :

C:\android\scrcpy\scrcpy-noconsole.vbs -S --always-on-top --stay-awake --no-audio --keyboard=uhid

Look:

image

I use some script to call adb commands to move and tap for some time, if that helps... It's also on Honor Magic 4 pro, with Android 13.

tomkrall commented 4 months ago

Only noticed it cause game was lagging. Probably had had it running 24hr at that point.

Running over wifi - scrcpy-win64-v2.4\scrcpy.exe --tcpip=192.168.1.40:5555

image

rom1v commented 4 months ago

There's definitely a leak somewhere (in scrcpy? in ffmpeg? in sdl? in graphics drivers?), but difficult to debug to know where since I don't reproduce.

In that session of 24hr, did you also control the device? Does it also happen with --no-control? (With previous messages, we know that it is not related to audio, since it also happens with --no-audio)

tomkrall commented 4 months ago

There's definitely a leak somewhere (in scrcpy? in ffmpeg? in sdl? in graphics drivers?), but difficult to debug to know where since I don't reproduce.

In that session of 24hr, did you also control the device? Does it also happen with --no-control? (With previous messages, we know that it is not related to audio, since it also happens with --no-audio)

I definitely interacted with the window/device a few times via scrcpy but it's mostly sitting without interactions. will try with no-control for awhile and report findings.

rom1v commented 4 months ago

Another interesting test to do: does it also happen with scrcpy --render-driver=software?

AndroidDeveloperLB commented 2 months ago

@rom1v Has anyone contacted you about this? Any progress? I can still have it reproduced. Not always, but for me it's when I let it stay while I play a game (Heroes of the storm). It can reach a ridiculous amount of RAM usage, and I notice it in the game itself (serious lags and PC beeping for some reason).

rom1v commented 2 months ago

Any progress?

No.

Could you please try to reproduce:

AndroidDeveloperLB commented 2 months ago

@rom1v

  1. Sadly the only other device (current one is Pixel 6 with Android 14) I currently have is the Honor Magic 4 pro (with Android 14), which fails to use ScrCpy with the screen turned-off feature. For this device, I use Android Studio mirroring, and even then only on the stable version because the canary version has the same issue as ScrCpy.

So it won't be the same test. Want to try it still? Note that the issue doesn't always occur.

For example, now that I started seeing huge memory consumption, it was this way: start ScrCpy, start game, play a bit, and during the game start Chrome-based web-browser that has a lot of tabs. Then for some reason ScrCpy started using GB of RAM. I had to kill it, and start it again.

As for another PC, I have a laptop, but it has issues playing the game (too old, probably).

  1. What about the --render-driver=software? Anyone tried it?

  2. I've noticed that when I play and go back to ScrCpy while the game is still running, ScrCpy might show the wrong content (frozen on something from the past). Could it be related? Might be a Windows OS issue? Maybe you could pause mirroring when the window is completely hidden, or at least when it's minimized? Unless of course you also record. I don't usually record using ScrCpy. My most common command is:

C:\android\scrcpy\scrcpy-noconsole.vbs -S --always-on-top --stay-awake --no-audio --keyboard=uhid --no-mouse-hover
tomkrall commented 2 months ago

In a similar fashion, I would let it run while playing PUBG. But it also doesn't let render anymore when I'm in game and have switched to running with software render. I haven't noticed the excess memory but tbh I also haven't been running it as long. Will let it go nuts these coming weeks. scrcpy-win64-v2.5\scrcpy.exe --tcpip=192.168.1.40:5555 --no-audio --render-driver=software On Sunday, July 7, 2024 at 10:04:39 AM EDT, AndroidDeveloperLB @.***> wrote:

@rom1v Has anyone contacted you about this? Any progress? I can still have it reproduced. Not always, but for me it's when I let it stay while I play a game (Heroes of the storm). It can reach a ridiculous amount of RAM usage, and I notice it in the game itself (serious lags and PC beeping for some reason).

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>