[Gambas-user] Returning locally instantiated Classes & Collections from Functions.

sbungay sbungay at ...981...
Fri Aug 18 22:26:19 CEST 2006


   OK. The local reference to the global instance gets destroyed but 
because we were assigning another reference to the object, the object 
itself continues to live. Garbage collection occurs when all references 
to an object are destroyed?
   Sorry if I'm parroting things back... I just want to understand whats 
happening.

Steve.

Benoit Minisini wrote:
> 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,
> 




More information about the User mailing list