Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

V - when memory gets freed

Tags:

vlang

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?

like image 283
Thomas S. Avatar asked Sep 07 '20 08:09

Thomas S.


1 Answers

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

like image 171
Nick Treleaven Avatar answered Mar 28 '23 10:03

Nick Treleaven