Comments (8)
I have modified the script to allocate a significant amount of memory with Leak_sample
and then read a 30MB randomly generated file and GC does end up collecting the Leak_sample
objects when the process needs more memory (when we reach --max-old-space-size
). There is no leak here. Appreciate the help @XmiliaH !
from vm2.
This library does not add any properties to Object.prototype
. Furthermore, I do not know what the gc
function does.
The only thing I can say is that the posted code should not leak memory.
from vm2.
@XmiliaH I did not say it adds properties to Object.prototype
. The code still touches it though, in bridge.js.
global.gc()
forces the Garbage collector to run. Node exposes it if you run the script with the --expose-gc
flag.
I can reproduce this behavior deterministically. If you run node --expose-gc --inspect vm2_leak.js
and take heapdumps with Chrome, you should also see that all Leak_sample
objects are kept in memory even though we're already out of main()
scope. Did you try to reproduce it yourself?
from vm2.
No, I did not try to reproduce this as I do not know what gc
does and what it guarantees as it is possible that it will not collect the context object from vm
modules which is a special object.
from vm2.
@XmiliaH if I understand correctly, the object is currently being kept in memory due to a closure in Object.prototype.__defineGetter__
, which the lib also touches in setup-sandbox.js, not really related to the vm
context object.
from vm2.
Yes, we put the __defineGetter__
function into a WeakMap
as seen in the image. But that should remove the entry when the key becomes dead.
from vm2.
I see in this comment that vm
contexts used to not be collected due to GC heuristics (only really collected once we hit --max-old-space-size
) but it's no longer the case in newer Node versions. I'm experiencing this in Node v14.19.0
, however. Am I right by saying this is what's happening here? GC just does not want to dispose of the vm
context because it has available memory elsewhere and this keeps the context Object.prototype
copy in memory alongside everything else?
from vm2.
I do not fully know how the vm
context object integrates with the garbage collector, but I would assume that this is the case.
from vm2.
Related Issues (20)
- freeze doesn't work on Array methods (shift, pop, etc) HOT 4
- fetch not available in vm2 with node 19 HOT 1
- VM and NodeVM behaves differently on await HOT 3
- Any tips for improving performance of `vm.run()`? HOT 9
- [VM2 Sandbox Escape] Vulnerability in [email protected] HOT 13
- Sandbox Escape in [email protected] HOT 3
- Adding a Security Policy HOT 1
- Modules not loading any more? HOT 16
- Overriding functions of objects from sandbox parameter inside NodeVM HOT 3
- Accessing .buffer property on a Float32Array HOT 8
- Hello, is there any way to make the large functions in node equal to those in VM2? Or not isolate large functions? HOT 16
- Usage with NextJS HOT 8
- this.pathResolve is not a function in 3.9.18 HOT 2
- Work in a bundle HOT 3
- Use external modules without filesystem access HOT 1
- Typescript Set transpilation issues
- Node's test runner not available as builtin
- Isolating Imported Modules
- Discontinued HOT 63
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vm2.