Allocating and deallocating structs with new and delete

Im trying to do the following:

MyStruct :: struct {
   ...
}

main :: proc()
{
   handle := new(MySruct)
   defer delete( handle )
}

But I get the following compiler error:

“Error: No procedures or ambiguous call for procedure group ‘delete’ that match with the given arguments”

I don’t understand this…

new allocates arbitrary type on the heap, it’s paired with free. make initializes a builtin type and it’s paired with delete. You’re simply pairing the wrong things…

See the allocator section: Overview | Odin Programming Language

As for the specific error message, delete is a proc group and it doesn’t have a matching variant for your struct that’s why it complains: package builtin - pkg.odin-lang.org

1 Like

Thanks! Now I’ve learned about the distinction between new/free and make/delete
(a bit confusing for a newbe, I must say)