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

How to destroy the memory of the string field in JSON #3208

Closed
heibor opened this issue Sep 10, 2019 · 1 comment
Closed

How to destroy the memory of the string field in JSON #3208

heibor opened this issue Sep 10, 2019 · 1 comment
Labels
question No questions on the issue tracker, please.
Milestone

Comments

@heibor
Copy link

heibor commented Sep 10, 2019

I wrote a test to use std.json, the code is here.

In the line 57, I want to destroy the memory for the path, butIt seems that the memory leaked.

Is there a way to destroy the momory for the variable path?

@andrewrk andrewrk added the question No questions on the issue tracker, please. label Sep 10, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Sep 10, 2019
@tiehuis
Copy link
Member

tiehuis commented Sep 10, 2019

When the Parser is used to construct a tree of json objects, these are allocated using an arena allocator. It isn't possible to free memory for a single object in the tree with the current api.

I'm not particularly attached to any method of handling objects. My initial thought for using an arena was to speed up the allocation of many objects and simplify clean-up. Also, I considered that the use-case for a tree is typically as a query object and you want to keep all values in the tree around until you are done. Open to any suggestions to change if it makes sense.

Just to add specifically on your example, the tree.deinit() call will clean up memory after you spawn the thread so you don't need to free that specific path. If you need the path to exist for the thread however, you will need to make your own copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question No questions on the issue tracker, please.
Projects
None yet
Development

No branches or pull requests

3 participants