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

Add GC #57

Open
bananu7 opened this issue Sep 24, 2018 · 2 comments
Open

Add GC #57

bananu7 opened this issue Sep 24, 2018 · 2 comments

Comments

@bananu7
Copy link
Owner

bananu7 commented Sep 24, 2018

Yay. Probably a regular, pause-the-world mark-and-sweep?

Ideally the GC would be done without polluting the original data model ("mark" in "mark-and-sweep" requires a way to mark objects w/o references), but I'm not sure how feasible that would be. Perhaps an ad-hoc GC-specific Value wrapper just for the time of GC collection?

@bananu7
Copy link
Owner Author

bananu7 commented Jul 23, 2019

So the way it would work

type Refcount = Int
data GCValue = GCValue Value Refcount

The only objects that can be cleaned are functions and tables. The global table implicitly extends lifetimes of everything touched by it.

Maybe instead of GCValue it's enough to have GCTableData and GCFunctionData

Then I would go over those two tables separately. First, each of them gets marked with 0. Then, I go through all the tables (starting with the global one) and for every table ref I find the appropriate table and ping it.

This wont work properly when two tables form a cycle. That would require tracking references from global separately somehow

@bananu7
Copy link
Owner Author

bananu7 commented Sep 19, 2021

The gc branch doesn't currently merge cleanly, but those changes aren't that important. What's more important is MonadState Context currently introduced. I think the direct access to the context is valuable, but it's probably the point where those things should only be exported to some internal module or something, or simply just exported as separate functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant