Mojo + GC

Does Mojo support (optional) GC? If so, does it implement a modern GC like the JVM (e.g. ZGC)? If not, does it just do reference counting? GC is important, of course, for workloads with large numbers of short-lived objects, e.g. as is the case for persistent data structures. Wondering how general-purpose Mojo is intended to be.
4 Replies
Ryulord
Ryulord10mo ago
Mojo doesn't use GC. Instead it does automatic memory management with a borrow-checker similar to rust. Basically the compiler inserts mallocs and frees at compile time so that things are as fast as possible at runtime just like if you were using manual memory management. The downside is that in order for the compiler to do this you need to introduce something called an ownerhsip and borrowing model that programmers need to understand and think about while programming.
Alex Gunnarson
Alex GunnarsonOP10mo ago
Ah, got it. So it will introduce cognitive overhead to the level that Rust currently does, then? Or is the borrow checker more sophisticated / easier to work with in some way?
sora
sora10mo ago
Not necessarily. Mojo's lifetime system is designed to be easier to work with: doc
Modular Docs - Ownership and borrowing
How Mojo shares references through function arguments.
Alex Gunnarson
Alex GunnarsonOP10mo ago
Awesome, thanks for the link!
Want results from more Discord servers?
Add your server