Awhile back I wrote a Rust implementation of the Monkey programming language by Thorsten Ball (https://monkeylang.org/). When I got done with it I was a bit surprised that I never used an Arc/Rc anywhere and didn't have a Garbage Collector and couldn't quite determine under what circumstances I'd need to build one. Being a relative novice at both Rust and language design and functional languages though I dropped that question due to being a bit mentally exhausted.
So my question is under what condition do you have to worry about Garbage Collection in the Monkey language and what kinds of tests would you have to write to exercise memory leaks in the language? Or alternatively what kinds of extensions would you need to write to the Monkey language where you would start to need a Garbage Collector? Clearly you'd need it if you were able to build circular data structures, but I actually don't know how to build those in Monkey. And for those unfamiliar with it, the language is purely functional and immutable.
I'll post more specific information about how I wrote the internal data structures in my implementation if it becomes necessary, but it pretty closely follows the go implementation in the books.
This question is very similar to Creating a new language with Rust without Garbage Collection? but I thought it was worth it to ask a concrete question about the Monkey language itself. And I think this has more to do with functional programming and language design than rust itself. I guess this question is closer to When do functional programming languages need advanced garbage collection?.
fn f(x) { fn(y) { y } } ; f(fn(z) { a + b })
there seems no obvious way to free the argument closure without some sort of collection strategy. Is that what you’re looking for (i.e. a code example), or is it more about Rust implementation strategies? Writing in Rust or not doesn’t make a huge difference to what the language requires in order not to leak memory, but the lifetimes you give may highlight where it can be happening. $\endgroup$