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

call C++ destructor instead of free #21

Merged
merged 2 commits into from
Sep 1, 2023
Merged

Conversation

dylanrb123
Copy link
Contributor

free will just free the memory for the pointer itself, by calling the native destructor it should actually free the underlying memory.

@dylanrb123 dylanrb123 requested a review from psobot September 1, 2023 16:40
@@ -277,6 +277,15 @@ public void close() throws IOException {
nativeDestructor();
}

@Override
protected void finalize() throws Throwable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is called by the JVM on garbage collection so the destructor will be called even if close isn't called

Copy link
Contributor

@markkohdev markkohdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @dylanrb123!
📝 ♻️ 🗑️

@dylanrb123
Copy link
Contributor Author

Tested this locally by building the JAR and loading that in a small java app that loads a large (14gb) index, closes it, and then just hangs. Monitoring the mem usage I was able to see it reclaim the memory as expected. Before this change even after the index was closed the memory was not released.

@dylanrb123 dylanrb123 merged commit b18086f into main Sep 1, 2023
46 checks passed
@dylanrb123 dylanrb123 deleted the call-cpp-destructor branch September 1, 2023 19:23
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