On 2024-01-15 3:51 PM, Frank Millman via Python-list wrote:
Hi all
I have read that one should not have to worry about garbage collection
in modern versions of Python - it 'just works'.
I don't want to rely on that. My app is a long-running server, with
multiple clients logging on, doing stuff, and logging off. They can
create many objects, some of them long-lasting. I want to be sure that
all objects created are gc'd when the session ends.
I did not explain myself very well. Sorry about that.
My problem is that my app is quite complex, and it is easy to leave a
reference dangling somewhere which prevents an object from being gc'd.
This can create (at least) two problems. The obvious one is a memory
leak. The second is that I sometimes need to keep a reference from a
transient object to a more permanent structure in my app. To save myself
the extra step of removing all these references when the transient
object is deleted, I make them weak references. This works, unless the
transient object is kept alive by mistake and the weak ref is never removed.
I feel it is important to find these dangling references and fix them,
rather than wait for problems to appear in production. The only method I
can come up with is to use the 'delwatcher' class that I used in my toy
program in my original post.
I am surprised that this issue does not crop up more often. Does nobody
else have these problems?
Frank
--
https://mail.python.org/mailman/listinfo/python-list