4,400
edits
m (→Problem) |
m (Use Nasal highlighter) |
||
Line 76: | Line 76: | ||
The mark/sweep algorithm can also be easily expressed using pseudo code, i.e. in Nasal itself: | The mark/sweep algorithm can also be easily expressed using pseudo code, i.e. in Nasal itself: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
var garbageCollect = func (roots) { | var garbageCollect = func (roots) { | ||
Line 89: | Line 89: | ||
The mark() function would just recursively check (i.e. calling itself) if the "marked" flag is set or not, and make sure to set the mark bit for all referenced objects: | The mark() function would just recursively check (i.e. calling itself) if the "marked" flag is set or not, and make sure to set the mark bit for all referenced objects: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
var mark = func (obj) { | var mark = func (obj) { | ||
Line 102: | Line 102: | ||
Finally, the sweep() function (reap() in the Nasal GC), will free all unreachable objects and reclaim the memory: | Finally, the sweep() function (reap() in the Nasal GC), will free all unreachable objects and reclaim the memory: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="nasal"> | ||
var sweep = func { | var sweep = func { |