Deleting temporary custom types in a function

Blitz3D Forums/Blitz3D Programming/Deleting temporary custom types in a function

Just return it without deleting the temporary type (object). You'll be returning a pointer to the object, which gets assigned to your own pointer before the temporary pointer goes out of scope, like so:

Function CreateThing.Thing ()
    t.Thing = New Thing ; Object created here and assigned to pointer t...
    Return t ; Return value of t -- pointer to the object...
End Function

mypointer.Thing = CreateThing () ; mypointer receives pointer to object...


This returns the value of t (pointer to the object) to mypointer. The pointer t will then go out of scope as the function is exited (so it's basically non-existent), but mypointer is pointing to the object itself, so you can free the object by deleting mypointer.