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

Fix memory leak in CallbackInput #201

Merged
merged 1 commit into from
Jun 19, 2024
Merged

Conversation

JJIngram
Copy link
Contributor

Issue

I noticed there was a large buildup of memory when repeatedly calling parse on a Parser. After digging into the issue it turns out that input, and therefore inputString, was being retained by CallbackInput

input = (offset, _position) => inputString.slice(offset)

Fix

This PR simply resets the resources in the destructor of CallbackInput to allow input and inputString to be garbage collected.

@tree-sitter tree-sitter deleted a comment from Pullerz Jun 10, 2024
@amaanq amaanq merged commit d07a2ad into tree-sitter:master Jun 19, 2024
7 checks passed
@amaanq
Copy link
Member

amaanq commented Jun 19, 2024

thanks!

@maxbrunsfeld
Copy link
Contributor

@JJIngram Just curious - do you know why we'd need to reset those handles in the destructor, when the handles are about to have their destructors called anyway?

@amaanq
Copy link
Member

amaanq commented Jun 20, 2024

My guess is, and correct me if I'm wrong, if you call parse a ton of times within a short timespan, not all the strings have had their destructor(s) called yet, leading to the buildup if done so within a short time frame? At least that's how I interpreted it, I probably should have tried to reproduce first

@PandelisZ
Copy link

I can confirm the above was discovered through many many many many calls to this api happening in very short time spans yes.

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.

4 participants