You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linux lion-gram 5.4.0-64-generic #72~18.04.1-Ubuntu SMP Fri Jan 15 14:06:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Run this script
while(true){newWeakRef({});}
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
After each loop the newly created object {} should get garbage collected. Eventually the weak ref to that object should get garbage collected too. So the application should run forever with memory increasing and decreasing as gc kicks in.
What do you see instead?
The process memory increases linearly until ~2.5GB then crashes with
Analyzing the issue further seems that any object passed to the constructor of WeakRef is hold forever. I have other examples that cause an OOM with WeakRef usage:
Example with logs to visualize linear memory growth until OOM
If your code has just created a WeakRef for a target object, or has gotten a target object from a WeakRef's deref method, that target object will not be reclaimed until the end of the current JavaScript job (including any promise reaction jobs that run at the end of a script job)
So to prevent causing an OOM, let the event loop tick:
Version
v16.8.0
Platform
Linux lion-gram 5.4.0-64-generic #72~18.04.1-Ubuntu SMP Fri Jan 15 14:06:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Run this script
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
After each loop the newly created object
{}
should get garbage collected. Eventually the weak ref to that object should get garbage collected too. So the application should run forever with memory increasing and decreasing as gc kicks in.What do you see instead?
The process memory increases linearly until ~2.5GB then crashes with
Additional information
Analyzing the issue further seems that any object passed to the constructor of WeakRef is hold forever. I have other examples that cause an OOM with WeakRef usage:
Example with logs to visualize linear memory growth until OOM
The text was updated successfully, but these errors were encountered: