Open gjvnq opened 2 years ago
When constructing a parentless window as shown in the code, it will be destroyed when leaving the function. Apparently the icecream printer keeps a reference somewhere; so the window remains and is shown.
So we have a good idea of what is causing the bug and this seems to imply that icecream is likely to have memory leak problems.
After some testing, I have managed to discover that icecream.py:229 is causing the trouble. The Source.executing
method seems to be maintaining a reference to the local variables even its return value is discarded.
I discovered that adding gc.collect()
at the end of IceCreamDebugger.__call__
solves the problem.
--- a/icecream/icecream.py 2022-03-21 15:00:17.604475128 -0300
+++ b/icecream/icecream.py 2022-03-21 14:59:57.518886105 -0300
@@ -13,6 +13,7 @@
from __future__ import print_function
+import gc
import ast
import inspect
import pprint
@@ -216,6 +217,7 @@
else: # E.g. ic(1, 2, 3).
passthrough = args
+ gc.collect()
return passthrough
def format(self, *args):
@gjvnq wonderful digging and homework. that's extremely helpful. thank you! 🙏
strange. the fact that gc.collect()
fixes the issue means there's a reference cycle somewhere. otherwise the reference gc would have freed the objects
@gjvnq sanity check: you're running your pyside+icecream app with cpython, right? or a different python interpreter?
garbage collection can be computationally expensive. we dont want to run a gc sweep after every ic()
call. @alexmojaki any idea where there might be a reference cycle in executing?
I'm running cpython on a macOS 11 machine.
Em ter., 22 de mar. de 2022 15:23, Ansgar Grunseid @.***> escreveu:
@gjvnq https://github.com/gjvnq wonderful digging and homework. that's extremely helpful. thank you! 🙏
strange. the fact that gc.collect() fixes the issue means there's a reference cycle somewhere. otherwise the reference gc would have freed the objects
@gjvnq https://github.com/gjvnq sanity check: you're running your pyside+icecream app with cpython, right? or a different python interpreter?
garbage collection can be computationally expensive. we dont want to run a gc sweep after every ic() call. @alexmojaki https://github.com/alexmojaki any idea where there might be a reference cycle in executing?
— Reply to this email directly, view it on GitHub https://github.com/gruns/icecream/issues/118#issuecomment-1075476534, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXIYHEHUJBOVZ53QPCEVMTVBIF2JANCNFSM5RFAZNNQ . You are receiving this because you were mentioned.Message ID: @.***>
When I use
ic
instead ofprint
, the widget shows up as a black screen instead of none at all.I suspect that icecream is doing some weird magic that is triggering some function calls that should not have been made.
Bug report on Qt's end: https://bugreports.qt.io/browse/PYSIDE-1866