Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
GC not works as expected with crypto module #5949
Here's a simple program that encrypts 16MB data 100 times:
And we can see the gabage collector not work as expected. RSS went up to 300MB, after the encryption it never went down.
I also found that a simple loop of
That's not unexpected. It's an artifact of how buffers and the garbage collector interact.
The V8 GC takes a lazy approach to memory management, it tries to do as little work as possible because garbage collection is expensive.
The flip side of that is that buffers - which are essentially tiny JS objects that point to memory outside of the JS heap - tend to live longer and hold on to that external memory longer than is strictly needed.
It has been addressed to some extent in master but the basic issue will never go away completely. If that's a problem for you, you'll have to invoke the garbage collector manually from time to time.