|
From: Thomas C. <tca...@gm...> - 2015-03-08 19:44:23
|
My knee-jerk reaction is to move the definition of `format` outside of the `Visualize.__init__` method. If you need to have hooks back into the visualize method I would use a function factory + weak refs or a class (again with weakrefs) with a `__call__` method. Tom On Sun, Mar 8, 2015 at 3:35 PM Sebastian Berg <seb...@si...> wrote: > 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 > ------------------------------------------------------------ > ------------------ > Dive into the World of Parallel Programming The Go Parallel Website, > sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for > all > things parallel software development, from weekly thought leadership blogs > to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |