altv-js-module icon indicating copy to clipboard operation
altv-js-module copied to clipboard

Client side memory leak

Open xxshady opened this issue 2 years ago • 12 comments

Description of the problem

Reproduction steps

Reproduction steps

  1. Check heap size in console image

  2. reconnect

  3. Check heap size in console again image

Expected behaviour

No memory leak!!

Additional context

No response

Operating system

Windows 11

Version

dev/10.0-dev12

Scope

client

xxshady avatar Apr 14 '22 00:04 xxshady

It's nothing new that Client JS is full of memory leaks and unfortunately they are very hard to track down

LeonMrBonnie avatar Apr 14 '22 08:04 LeonMrBonnie

Step 2. Reconnect

Well there's your problem.

Stuyk avatar Apr 14 '22 12:04 Stuyk

Step 2. Reconnect

Well there's your problem.

@Stuyk what do you mean?

xxshady avatar Apr 14 '22 12:04 xxshady

alt:V was never written with the intention of cleanup after reconnect. Yes it's a nice to have thing but there are certain things which cannot be cleaned up during the reconnection process. The code was written to be most performant during a single connection and a game reboot would be required to get that same performance on other servers.

Stuyk avatar Apr 14 '22 12:04 Stuyk

Its not about cleanup, its a memory leak in js module, that can be fixed (and yes, Leon already has replied that this is not an easy fix).

And yes I know that reconnect (resource restart) is only for development (ofc you cant use it without debug mode xd)

xxshady avatar Apr 14 '22 12:04 xxshady

Fix of this issue can improve js development experience on alt:V, nothing more

xxshady avatar Apr 14 '22 12:04 xxshady

if you have gamemode that eats 100mb of the heap on first resource start and if you do 10-20 reconnects (resource restarts) your game will freeze on each resource start every reconnect for 5 or more seconds because of the heap overflow

xxshady avatar Apr 14 '22 12:04 xxshady

I also noticed this when I tested my server, GTA even crashed :(

JustCup avatar Apr 14 '22 12:04 JustCup

For an "easy" fix we could maybe just "restart" the script runtime on reconnect, so that it creates a new isolate on every reconnect. This would definitely fix all memory leaks (at least those originating from JS objects... xd) but I don't know whether that will fuck other shit up

LeonMrBonnie avatar Apr 14 '22 13:04 LeonMrBonnie

and if this fix turns out to be possible, resource restart will be overboard?

xxshady avatar Apr 14 '22 13:04 xxshady

I just pushed 6074731e06e7a6e7ba03e69c2fa873841ec86976 which should definitely fix some memory leaks that existed before, someone can benchmark it to find out whether this improved anything

LeonMrBonnie avatar Apr 14 '22 14:04 LeonMrBonnie

i saw that, if u connect to the same server but without resources, it takes time to load resource but there no resources. if u connect server, turn off server, turn on server without resources, reconnect to the server, it's need time to load resources that not exists, maybe there is memory leak, because old resource still in memory

Iamproplayer7 avatar Jul 20 '22 14:07 Iamproplayer7