[Gambas-user] Class behavior: _free method
Benoit Minisini
benoit.minisini at gambas-basic.org
Thu Dec 15 18:14:02 CET 2022
Le 15/12/2022 à 18:08, T Lee Davidson a écrit :
> On 12/15/22 10:51, CD wrote:
>> Hello
>>
>> I join a test project that gives me 3 problems
>>
>> 1°) the class name during the instantiation is forced with a capital
>> letter:
>> clsTestClass becomes ClsTestClass.
>
> It doesn't behave that way here. I can choose "clsTestClass" from the
> auto-completion dropdown which also shows the public symbols of the class.
>
>>
>> 2°) As I must share the same instance between several procedures, I
>> declare it
>> without instantiating it in the declarations.
>> But when I instantiated it in one of the procedures, Gambas does not
>> offer me
>> the public members of the class.
>
> The program behaves as expected here even using the uppercase class
> name, "ClsTestClass". When having difficulties such as this, it might
> help to "Compile all" to make the IDE aware of new classes and/or class
> properties and methods.
Mmm... I'm not sure this is not a bug introduced recently. I will check
>
>>
>> 3°) The class contains a Timer, and when I free the instance, I
>> thought I could
>> free the Timer. It does not work!
>> First I have to free the Timer from outside the class, so that I can
>> free the
>> instance afterwards...
>
> There was a discussion of this some time ago. I think it was in regards
> to me trying unsuccessfully to close open sockets in the _free method.
> The issue, IIRC, was caused by the sequence of events that happen when a
> resource is freed, and, yes, it is to be expected. Unfortunately, I
> don't recall exactly how Benoît explained it. I'll have to see if I can
> find that discussion in the mailing list archive.
>
It's more simple than that: As soon an object A that raises events is
created inside another object B, the object A internally references the
object B as its "event observer". So B cannot be freed before the object
A is freed.
Specifically, to free the timer, you must stop it and release all
references on it.
Regards,
--
Benoît Minisini.
More information about the User
mailing list