Nasal GC Musings: Difference between revisions

Jump to navigation Jump to search
m
Line 25: Line 25:
* Function calls (which create a hash for the namespace)
* Function calls (which create a hash for the namespace)
* Closure binding with a "func ..." expression.
* Closure binding with a "func ..." expression.
The garbage collector used by Nasal is a mark/sweep collector. It works by first "marking" all objects that are currently in use by the program, then "sweeping" through memory and reclaiming any objects that were not marked. This is done using the mark and reap functions.
The mark function takes a reference to an object and recursively searches through all references that are reachable from that object, marking each one as in use. The reap function is called for each object type, and it searches through all objects of that type to find and free any that were not marked by the mark function.
The garbage collection process is initiated by the garbageCollect function, which is called when the garbage collector is needed. This function first searches through all contexts in the program to mark all reachable objects, then it marks several global objects, and finally it calls the reap function for each object type to free any unreferenced objects.
The garbage collector is called from several places in the code, including the naModUnlock function, which is called when a thread releases its lock on the global data structures. This allows the garbage collector to run concurrently with other threads, which can help improve performance. However, there are also situations where the garbage collector needs to run exclusively, such as when it needs to free the list of dead blocks. In these cases, the bottleneck function is called to engage the "bottleneck" and block all other threads until the garbage collector has finished running.


== mark/sweep GC ==
== mark/sweep GC ==

Navigation menu