Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.OutOfMemoryError: Java heap space #98

Closed
wants to merge 1 commit into from
Closed

java.lang.OutOfMemoryError: Java heap space #98

wants to merge 1 commit into from

Conversation

jacobshirley
Copy link

@jacobshirley jacobshirley commented Mar 14, 2024

Hi there, first of all, thank you for this library. It really is the best node/java library available!

However, I have hit an issue related to memory that I don't know enough about how the JVM/Rust works to solve. As can be seen in the PR, i've created a test to show the error I'm getting when repeatedly allocating memory. It gets to about iteration ~500 and then comes out with java.lang.OutOfMemoryError: Java heap space. Perhaps there is a memory leak somewhere?

If it helps, I'm running Ubuntu 22.04

@MarkusJx
Copy link
Owner

I'll have to take a closer look but the first thing that comes to my mind is that we are working with two different garbage collectors at this point. You are creating a buffer inside node.js which gets passed to Java.

The node process keeps the resulting ByteArrayInputStream instance wrapper alive since this process only owns these light-weight wrappers, which are not creating a high enough memory usage, forcing the gc to run.

The Java process can only destroy the buffers if the node process releases the ByteArrayInputStream wrapper, which it doesn't.

You might want to try forcing the node gc to run, which may resolve your issue. Otherwhise I could look into providing a method for manually releasing Java objects.

But these are all guesses, I'll have to take a closer look, which may take a while.

@jacobshirley
Copy link
Author

Thanks for the response. I suspect as you say, it's a garbage collection timing issue, where the memory is probably not getting released quick enough. I have just tried triggering the node garbage collector via global.gc() but no luck unfortunately.

A free type function which could release objects would be ideal though, without having to find ways around the node/Java garbage collection process.

@MarkusJx
Copy link
Owner

Funny thing, there was actually a memory leak. Will be fixed in #99.

Also added a new option to manually delete java references, which is still required when creating large objects inside the Java VM, since garbage collection is not guaranteed by the V8.

I'll close this merge request in favor of #99 since the JVM needs to be destroyed and re-created in order to set memory limits, which is not supported by this package due to memory safety issues.

@MarkusJx MarkusJx closed this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants