Sebastian Berg
2015-03-08 19:00:37 UTC
Hey,
probably there is nothing to help me here, but I have a QtGui, using
matplotlib and basically end up in a circular reference hell that is not
resolvable by the gc. After removing almost all circular references, the
python inherited QWidget that embeds the figurecanvas is now deleted
fine.
The thing I end up with however is something like
class Visualize(object):
def __init__(self):
self.figure = Figure()
canvas = FigureCanvas(self.figure)
PythonInheritedQtWidget(self).element.setWidget(canvas)
def format(*args):
# do stuff
return something
self.axis = self.figure.add_subplot(1, 1, 1)
self.axis.format_coord = format
# This was completely drawn with canvas and all
# PythonInheritedQtWidget is deleted fine.
I have not been able to get a minimal test case. But I have it pinned
down that everything can get cleaned up after:
del Visualize.axes.format_coord
so the circular reference that makes it not collectable is only the
format_coord which is a method pointing to the class owning the figure
and the axis. I am about to just use a weak reference wrapper function
to break the circle but it seems silly.
Anyway, I do not expect that anyone can help, and I expect it is some Qt
stuff really, but this is seriously annoying me....
- Sebastian
probably there is nothing to help me here, but I have a QtGui, using
matplotlib and basically end up in a circular reference hell that is not
resolvable by the gc. After removing almost all circular references, the
python inherited QWidget that embeds the figurecanvas is now deleted
fine.
The thing I end up with however is something like
class Visualize(object):
def __init__(self):
self.figure = Figure()
canvas = FigureCanvas(self.figure)
PythonInheritedQtWidget(self).element.setWidget(canvas)
def format(*args):
# do stuff
return something
self.axis = self.figure.add_subplot(1, 1, 1)
self.axis.format_coord = format
# This was completely drawn with canvas and all
# PythonInheritedQtWidget is deleted fine.
I have not been able to get a minimal test case. But I have it pinned
down that everything can get cleaned up after:
del Visualize.axes.format_coord
so the circular reference that makes it not collectable is only the
format_coord which is a method pointing to the class owning the figure
and the axis. I am about to just use a weak reference wrapper function
to break the circle but it seems silly.
Anyway, I do not expect that anyone can help, and I expect it is some Qt
stuff really, but this is seriously annoying me....
- Sebastian