[Gambas-user] Returning locally instantiated Classes & Collections from Functions.
Benoit Minisini
gambas at ...1...
Fri Aug 18 21:07:30 CEST 2006
On Friday 18 August 2006 19:08, Stephen Bungay wrote:
> Something tells me that we can't do this in gambas. If we have a function
> that instantiates an instance of a class (or a collection that contains
> instances of a class) and we return that instance, it will always return a
> NULL object because the local instance gets destroyed when the function
> ends.. Is this reasoning correct?
>
> Steve.
>
No. :-)
There is no "local instance". All instances are global. There are just local
variables that own a reference on an instance. This reference is lost when
you return from the function, but as you return another reference on the same
object, the object reference count does not move, and so the object is not
destroyed.
"Reference" is another name for memory address, with a "reference count"
associated with its memory address.
Regards,
--
Benoit Minisini
More information about the User
mailing list