Is it never a good idea to use as a return value, a reference to an object created inside a function from a local variable?
If the return value of the function is assigned to, let's say a global variable, will the reference to the return value still be valid when the function exits, or since the local variable is now referenced by a global pointer, will it remain valid after the function exits?
Example:
Is g valid after the function exits (and therefore the local variable awesome is eventually garbage-collected)?
(I'm trying to interface with the API from an external DLL and occasionally need to create object instances inside functions which are passed as return values to mirror the API behavior in BMax).
If the return value of the function is assigned to, let's say a global variable, will the reference to the return value still be valid when the function exits, or since the local variable is now referenced by a global pointer, will it remain valid after the function exits?
Example:
Function CreateNewAwesomeThing:TAwesomeThing() local awesome:TAwesomeThing = New AwesomeThing ... return awesome End Function global g:TAwesomeThing = CreateNewAwesomeThing()
Is g valid after the function exits (and therefore the local variable awesome is eventually garbage-collected)?
(I'm trying to interface with the API from an external DLL and occasionally need to create object instances inside functions which are passed as return values to mirror the API behavior in BMax).