I have a Python client application that communicates with a server. When an object is no longer used on the client side (i.e. ref count reaches zero - using CPython), I need to send a message to the server so it could clean the corresponding memory.
From Python's data model page __del__ documentation, I know that the mentioned special method is called when the ref count reaches zero, so implementing it to send a message to the server would possibly suffice.
I wanted to ask whether there is a more reliable approach, possibly by using the garbage collector (perhaps by adding a callback using gc.callbacks). I'm not sure if all Python objects are handled by it though.
Any help on the most robust way to call clean ups after an object is no longer referenced would be appreciated.