In FreeBASIC, a reference is in fact an internal pointer (created by the compiler) which is implicitly dereferenced when user want to access the reference.In the bugged code, the internal pointer points to a local instance (which is so destroyed when returning from the function).