-
Notifications
You must be signed in to change notification settings - Fork 85
Fix object lifetime management #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
hm: it turns out that calling |
Those are common mis-conception about garbage collectors:
|
Also GC is robust enough to handle circular references. The main two root causes of memory leaks, are global objects (examples: a global cache, module variables, etc), and lambda functions, unlike typical objects, where leaks are visible in the object graph through attributes, lambda functions keep references to objects simply because the lambda code uses them, which makes them hard to notice. |
Isn't python's main memory reference counting? I'm not sure how exactly it is implemented in cpython, but the other refcounting implementation I have experience with (C++'s smart pointers) frees memory of objects which's reference count reaches zero immediately. (This is also a very fast operation...)
sure, but as soon as the refcount of the lambda function reaches zero, it should be deleted... |
A memory freed does not mean the process memory goes down immediately, a process always keep the memory pages for fast re-allocation. |
sure, but I assume that the heap allocators will free memory eventually (in my case "eventually" means after deleting a > 5 GB |
(I strongly suspect that there are cycles in the reference graph of |
If it has no reason to (OS didn't ask for the RAM back, due to pressure from other processes), it has no reason to give it up. |
I would be surprised if there was a formal "out of band" mechanism of the Linux kernel to signal to userspace that there is memory pressure... |
The odxtools database object currently seem to mess up python's garbage collector: when running
the memory used by the
db
object is not freed after the "database deleted" string is printed but only at program exit, i.e., after "done" appears.I suspect that this is due to python's garbage collector getting confused by cyclic references, but unfortunately I have not found a good way to debug this, and my limited experiments with weak references from python's
weakref
module also did not fix the issue. @kayoub5, @nada-ben-ali, @zariiii9003: any ideas how to get to the bottom of this?The text was updated successfully, but these errors were encountered: