This issue is discussed in #41
Basically, in code like this:
Foo: class <T> {
val: T
init: func (=val)
}
The following C code is generated:
void Foo___defaults___impl(FooClass* this) {
types__Class___defaults___impl((types__Class*) this);
this->val = Memory__alloca(this->T->size);
}
The result is that the generic value is actually a dangling pointer.
To solve this, one can currently do:
Foo: class <T> {
val: __onheap__ T
init: func (=val)
}
And then manually free the generic value.
As discussed in that PR, I believe the best course of action would be to automatically assume __onheap__ for "naked" (non pointer) generic values and autogenerate a free function that deletes them and calls the user defined __destroy__ function (if a free function is not user defined).
This issue is discussed in #41
Basically, in code like this:
The following C code is generated:
The result is that the generic value is actually a dangling pointer.
To solve this, one can currently do:
And then manually free the generic value.
As discussed in that PR, I believe the best course of action would be to automatically assume
__onheap__for "naked" (non pointer) generic values and autogenerate a free function that deletes them and calls the user defined__destroy__function (if a free function is not user defined).