[PyQt] Re: Virtual methods and an extra reference

Sundance sundance at ierne.eu.org
Fri Jun 20 12:14:49 BST 2008


Kevin wrote:

> Obviously the usage of the above bound_ref is just for bound
> methods--but I think using new.instancemethod is more correct than
> lazily grabbing the bound method with getattr.

Hi Kevin,

I like the use of new.instancemethod. I like it a /lot/. However: I 
notice that your code increases the refcount to both the class and 
function object as a side effect of creating the weak reference, which 
gives me pause. Has this been a problem for you?

> The only issue 
> remaining is to whip up a C implementation :-)  This is important
> enough that I'll try to look into it today, 

Have you made progress on this?

In the meanwhile, I've been able to work around the memory leak by:

1) Renaming all my whateverEvent() methods to _whateverEvent(), and
2) Implementing a __getattr__() that returns 
WeakCallableRef(self._whateverEvent) when whateverEvent is requested.

At first I tried to make it work with a decorator, which would arguably 
have been remotely cleaner, but it works not, because the decorator 
acts on the unbound function object, not on the bound method.

The workaround makes my skin crawl. :| I hope you'll be able to whip up 
a fix, Kevin.

-- S.


More information about the PyQt mailing list