Struct phoenix_lang::gc::GC
source · pub struct GC {
pub instances: Vec<HeapObj>,
/* private fields */
}Expand description
The garbage collector. Let’s go
Important note to make sure I never break the GC: The only way we can deallocate something that we didnt mean to is if we have a PhoenixPointer somewhere other than the stack, globals, or in a reachable HeapObj So be careful if we ever alloc a PhoenixClosure or a PhoenixInstance when a PhoenixPointer is floating around on the rust stack => ie popping a value off, calling alloc, and then doing something with that value. If that value is the last pointer to an instance, it’ll cause the instance to be deleted
Ideas for making this not have placeholder values / fewer placeholder values: Steps to making it work:
- Use a linked list for instances
- When removing a value, replace the node with a placeholder
- When removing a value next to a placeholder, merge the two together and increment a counter in the placeholder
- When traversing the linked list, a placeholder is worth {counter} slots
- When allocating values, use the same queue but if it hits the middle of a placeholder, split it down the middle into two placeholders? => Ideally we would not but since the free_slots stack is not ordered in any way we don’t have any guarantees
This would get rid of most of the placeholder values but with a few problems A. The memory usage of the placeholders is minimal already B. Placeholders don’t necessarily “leak”, ie: running the program for a long enough time will not cause a memory shortage unless the code itself had used that much memory without GC’ing C. Linked lists and doing those traversals will undoubtedly be slower than the current Vec implementation, will it even be worth it?
All in all, I think I’ll need to wait until I have some code to profile.
Fields§
§instances: Vec<HeapObj>