V - when memory gets freed

1.2k Views Asked by At

V does have neither a manual memory release, nor a garbage collector (reference counting) nor an owner-based mechanism like Rust. How does it decide when to free memory?

1

There are 1 best solutions below

0
On

You can manually manage memory in V if you like by calling C.malloc and C.free.

V has experimental support for automatically freeing memory when it is no longer referenced. Use v -autofree, but there may be bugs for now. It allows some borrowing of owned memory when the reference doesn't escape. When it does escape, V will reference count the allocation.

It is influenced by Lobster: https://aardappel.github.io/lobster/memory_management.html