Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-25 Thread Richie Hindle
[Tim] > there's no 100% guarantee that a __del__ method will ever get called Can anyone point me to any definitive documentation on why this is the case? I was under the impression that __del__ would always be called: 1. for objects not in cycles and with no references 2. for objects whose o

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-24 Thread Tim Peters
[Tim] >> I'll note that one fairly obvious pattern works very well for weakrefs >> and __del__ methods (mutatis mutandis): don't put the __del__ method >> in self, put it in a dead-simple object hanging *off* of self. Like >> the simple: >> >> class BTreeCloser: >> def __init__(self, btree):

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-24 Thread Mike C. Fletcher
Tim Peters wrote: [Mike C. Fletcher] I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate __del__ methods (and the memory leaks they create). A worthy goal! Well, as of now it seems to have eliminated the last leaks in TwistedSNMP, and that's likely going to eliminate

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-24 Thread Richie Hindle
[me] > why the `self.btree = None` in the last line? [Mike] > It's to allow the Closer object to act as a substitute for a .close() > method on the object [...] If the user explicitly calls storage.close() > we don't want the __del__ trying to re-close the storage later. In > other words, its a

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-24 Thread Mike C. Fletcher
Richie Hindle wrote: [Tim] I'll note that one fairly obvious pattern works very well for weakrefs and __del__ methods (mutatis mutandis): don't put the __del__ method in self, put it in a dead-simple object hanging *off* of self. Like the simple: class BTreeCloser: def __init__(self, btree)

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-24 Thread Richie Hindle
[Tim] > I'll note that one fairly obvious pattern works very well for weakrefs > and __del__ methods (mutatis mutandis): don't put the __del__ method > in self, put it in a dead-simple object hanging *off* of self. Like > the simple: > > class BTreeCloser: > def __init__(self, btree): >

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-23 Thread Tim Peters
[Mike C. Fletcher] > I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate > __del__ methods (and the memory leaks they create). A worthy goal! > Looking at the docs for 2.3's weakref.ref, there's no mention of whether the > callbacks are held with a strong reference. A callback

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-23 Thread Mike C. Fletcher
Alex Martelli wrote: Mike C. Fletcher <[EMAIL PROTECTED]> wrote: weakref.ref( self, self.close ) but the self.close reference in the instance is going away *before* the object is called. Uh -- what's holding on to this weakref.ref instance? I guess the weakreference _itself_ is goin

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-23 Thread Alex Martelli
Mike C. Fletcher <[EMAIL PROTECTED]> wrote: > weakref.ref( self, self.close ) > > but the self.close reference in the instance is going away *before* the > object is called. Uh -- what's holding on to this weakref.ref instance? I guess the weakreference _itself_ is going away right afte

Weakref.ref callbacks and eliminating __del__ methods

2005-01-23 Thread Mike C. Fletcher
I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate __del__ methods (and the memory leaks they create). Looking at the docs for 2.3's weakref.ref, there's no mention of whether the callbacks are held with a strong reference. My experiments suggest they are not... i.e. I'm