[Gambas-user] How to free an object with an active ServerSocket?

T Lee Davidson t.lee.davidson at gmail.com
Tue Dec 8 03:10:34 CET 2020


On 12/7/20 7:07 PM, Benoît Minisini wrote:
> Le 08/12/2020 à 00:21, T Lee Davidson a écrit :
>> I have a project using a class that implements a ServerSocket.
>> In Form_Close(), set the object variable to Null so the object's _free method will get called.
>> But, with a ServerSocket actively Listening in that object, the _free method does not get called.
>>
>> Is this by design? Am I doing something wrong? What is the proper manner in which to free an object with an active server?
>>
> 
> It's the contrary. As Listen() references the SocketServer object, you must call the Close() method so that it can be freed 
> later. You should never have to implement the _free() method.

And that is what I attempt to do in the _free() method:
Public Sub _free()
   Print "FREE"
   MyServerSocket.Close
End

If I understand correctly, _free() is not getting called because Gambas is waiting for the active SocketServer to be Close'd.

So then, are you saying that I should implement a Close() method in the Tester class instead of relying on _free()?
Public Sub Close()
   MyServerSocket.Close
End

That doesn't make object sense to me because the internal workings of the Tester object should be privately encapsulated. (And, 
there is no Open() method.) But, if that is what will work, then that's what I'll do.


-- 
Lee


More information about the User mailing list