[Gambas-user] Dynamic Objects

Doriano Blengino doriano.blengino at ...1909...
Fri Apr 3 12:51:19 CEST 2009


Benoît Minisini ha scritto:
>> Rodney Rundstrom ha scritto:
>>     
>>> Thanks for that I'll work thought over the next few day. One last
>>> question on dynamic object (I think) how do we delete them and release
>>> the memory?
>>>       
>> This is a matter unclear to me, anyway: an object is freed when no
>> reference to it are in effect. 
>>     
>
> What is unclear in the last sentence?
>   
"How to release objects", is slightly unclear to me; this is because I 
am coming from another language, where objects have explicit Destroy and 
Free methods. I did little of this matter in gambas: for most 
situations, the automatic mechanism is pretty good; I did run in trouble 
when I used Observers, and I had to use an ugly hack. I also asked you 
about it, if you remember... anyway I solved.
>> When you instantiate a visual control,
>> its parent gets a reference to the object. I don't know how to delete
>> that reference (perhaps a Delete() method of its Children property?).
>> For forms, a Persistent property says what to do when the form is
>> closed, either hide it or destroy it. For other objects, I don't know -
>> better someone else replies to you.
>>
>> Regards,
>> Doriano
>>
>>     
>
> When an object exists only in the Gambas interpreter, like a Collection for 
> example, then it is referenced only by other Gambas objects. It is destroyed 
> when you release the last reference on it.
>
> But for objects existing outside of the Gambas interpreter, it is different. 
> GUI controls are in that case: they are internally referenced by the QT 
> library, so they are not destroyed when you have no reference on them anymore: 
> the GUI widget must be destroyed too. Hopefully, as you noticed, there is a 
> Delete() method that asks the GUI to destroy a widget if you need.
>
> Hope things are clearer...
>   
Yes, it is what I thinked... it is simply a matter of explanations. The 
best would be to have a uniform mechanism (and, in fact, it is already 
so, but it could seem unclear). What I want to say is: in object pascal, 
there is no automatic freeing of objects, but when you destroy an object 
which owns other objects, they are destroyed too (this makes sense). It 
does not matter if objects are GUI or non-GUI, the behaviour is always 
the same: if you don't touch them, they live. If you destroy them, they 
die. This is uniform. In gambas this is not possible, because if you 
instantiate a label at runtime, and then exit the routine, you don't 
want your label to be destroyed. But if instead of a label you 
instantiate a Collection, then you loose it, and probably this is what 
you want. Problem is, this is not uniform - ok, I understand that it is 
the only way to go: the automatic memory management of gambas is more 
important.


Regards,
Doriano



More information about the User mailing list