[Gambas-user] _free not called when object destroyed

BB adamnt42 at gmail.com
Wed Aug 2 23:13:20 CEST 2023

On 3/8/23 2:02 am, Brian G wrote:
> I have a question regarding when an object is destroyed and _free is 
> called.
> in my code when I do the following then the object free method is called
> dim a as myobject = new myobject
> a = new myobject     ' when I do this then the old object _free method 
> is called
> But if I
> a = NULL                  ' The _free method is never called for the 
> object or for any object in an array of objects
> Maybe I don't understand correctly how this works, but I would expect 
> the objects _free method to be called if there is no other reference.
(These are my thoughts, no testing done.) This is subtle. In the first 
case you mention "a" references a particular "myobject", then you 
implicitly destroy that object and its' reference pointer by using the 
creator again, so the _free event is raised. In the second case you are 
implicitly destroying the object but not it's reference pointer. Does 
that make sense?


More information about the User mailing list