Most objects (~90-100%) are freed by V’s autofree engine: the compiler inserts necessary free calls automatically during compilation. Remaining small percentage of objects is freed via reference counting.
For developers willing to have more low level control, autofree can be disabled with .
For example:
In fact, the first two calls won’t result in any allocations at all. These two strings are small, V will use a preallocated buffer for them.
struct User {
name string
}
number := 7 // stack variable
user := User{} // struct allocated on stack
numbers := [1, 2, 3] // array allocated on heap, will be freed as the function exits
println(numbers)
numbers2 := [4, 5, 6] // array that's being returned, won't be freed here
return numbers2