i am trying to store some method callbacks but referring to it will keep the bound object alive, so i tried to keep a weakref to method but that doesn't seems to be possible?
so
Why can't i keep a weak ref. to method (see example below)
What is the best way to keep method ref? any thing in standard lib? Or I will have to keep function and object ref. separate?
example:
import weakref
class A(object):
def m(self): pass
a = A()
import weakref
class A(object):
def m(self): pass
a = A()
rm = weakref.ref(a.m)
print "is weak ref to method dead?",rm() is None
print "Q1. why can't i keep weakref to bound method?"
ra = weakref.ref(a)
m = a.m
print "delete object"
del a
print "is object dead?",ra() is None
print "delete method"
del m
print "is object dead?",ra() is None
print "Q2. hmmm so i am stuck i can't keep a ref as it stops the object from gc, but weakref to method isn't working?"