On Mon, Oct 4, 2010 at 6:13 AM, Michael Droettboom <md...@stsci.edu> wrote: > The problem is when callbacks create cyclical references (which your > example does not). If the Handler class in your example needed to > update the figure or canvas in some way in the callback (which is a > common usage pattern), that cyclical reference prevents either from > being destroyed without running the cyclical garbage collector. And in > that case, you can't write a __del__ method on the handler to explicitly > disconnect the callbacks. >> In any case, if my logic is flawed (quite likely, since I imagine M. >> D. had a good look at this), it might be worth adding a >> >> .. warning:: >> >> section about this pattern to the event docs: >> >> http://matplotlib.sourceforge.net/users/event_handling.html >> >> because the problem is subtle and hard to diagnose (I just noticed it >> had also been reported recently >> http://sourceforge.net/mailarchive/forum.php?thread_name=4C9B7793.5020908%40gmail.com&forum_name=matplotlib-devel). >> > True -- it's non-obvious and confusing. On the other hand, the user is > no longer required to explicitly disconnect callbacks, which was the > source of many other subtle and hard to diagnose problems within the > matplotlib code itself. > > I'm still not completely happy with it, so I'd love to find a "third > way" if there's anything anyone can suggest.
Thanks for your explanation, it makes complete sense. I think it's OK, Eric just added a warning to the docs, which will go a long ways towards making this less of a user trap. Given the details you provided, I can't think of a generic way to handle these cycles 100% automatically. Using weakrefs seems like the most sensible solution, and users will just need to understand a little bit more before using this functionality. Event handling isn't raw beginner material in any case, so I don't think it's a huge problem. And if someone ever devises a clever solution to the problem, then great! But for now I think you can safely ignore this further. Regards, f ------------------------------------------------------------------------------ Virtualization is moving to the mainstream and overtaking non-virtualized environment for deploying applications. Does it make network security easier or more difficult to achieve? Read this whitepaper to separate the two and get a better understanding. http://p.sf.net/sfu/hp-phase2-d2d _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel