[Gambas-user] Using Classes

Benoit Minisini gambas at ...1...
Mon Apr 14 15:09:15 CEST 2008


On vendredi 11 avril 2008, MaxVK wrote:
> Hi, Id like to get something fully straight in my mind here:
>
> I have a class that I use to manipulate a treeview and some data that is
> connected to each treeview item. I have used a class for this so that I can
> call this code from any one of several forms that use treeviews in my
> project without the code becoming confused about the treeview that it is
> working on.
>
> I call the class in the header of my forms like this: PUBLIC DoTree AS NEW
> clsTree
>
> I can then access the functions in the class through DoTree.<function>, but
> my question is, do I need to explicitly destroy this class object (DoTree)
> in some way to prevent it from using memory when its not in use?
>
> For example, the first form in the project uses this class, but is only
> actually visible for a short period, and is hidden when another form opens.
> Do I need to clean up the class object (Dotree) while the form is hidden to
> prevent it hogging memory when it is not in use.
>
> Regards
>
> Max

Memory and object destruction is automatically managed by the interpreter.

Gambas use reference counting for that. See 
http://en.wikipedia.org/wiki/Reference_counting for more details.

If you want an object to be destroyed, you must release all its references, 
i.e. set NULL to all variables, array or collection slots having a reference 
on it.

Note that not everything is automatic. If you create circular references, i.e. 
an object A holding a reference of an object B, and the same object B holding 
a reference on the same object A, then the interpreter cannot release them 
automatically. You get a warning at program exit, and a list of all objects 
that couldn't be released.

Regards,

-- 
Benoit Minisini




More information about the User mailing list