6 ms·
Crumb is garbage collected (there is no need to manually allocated/deallocate memory)... though there is no background "garbage collector" process running... Th
by liamilan 3y ago
Crumb is garbage collected (there is no need to manually allocated/deallocate memory)... though there is no background "garbage collector" process running... The interpreter for Crumb is a tree-walk interpreter, and it just frees memory whenever it can... Crumb frees memory in the following cases:
1) When a function is finished, all memory related to the scope of that runtime is freed.
2) When an value is not returned out of a statement, or assigned to a variable, said value is freed.
3) When a function is applied, if an argument has no reference (it is not stored in a variable), it is freed.
4) Additionally, if the function itself has no reference (such as in the case of an immediately invoked function), it is freed.
Hope that clarifies things a bit :D
- gus_massa 3y agoSorry if I got the syntax wrong, but in something like f = { x = (list 1 2 3) y = (list x x) z = (get x 1) <- y } How does the compiler decides if it must free the memory used by x?
- s_Hogg 3y agoAll lists are passed by value and X isn't the return value, would be my guess
- yeputons 3y agoIt should. Everything is copied and by-value, there are no references/pointers or even closures, cycles are impossible. Think Pascal that has garbage collection for strings and dynamic arrays.
- _a_a_a_ 3y agoIt's an interpreter rather than a compiler, and looking at the code it seems to use ref counting
- gus_massa 3y agoRef counting makes a lot of sense with the description of the OP, and if there are no cycles it's good.
- deleted 3y ago[deleted]