[DB-SIG] Standardized "with" block behavior?
Ricardo Bugalho
ricardo.b at zmail.pt
Mon Sep 25 21:49:42 CEST 2006
Sorry about the last post. Clicked on send instead of clicking in
another application.
On Mon, 2006-09-25 at 12:28 +0200, M.-A. Lemburg wrote:
> Mario Frasca wrote:
> > On 2006-0925 10:27:16, M.-A. Lemburg wrote:
> >> Sounds reasonable, though strictly speaking, the with-container
> >> is not necessary, since cursors and connections will close
> themselves
> >> when garbage collected, ie. as soon as they go out of scope.
> >
> > this (garbage collected as soon as they go out of scope) is more
> > implementation dependent than absolutely true...
> >
> > the garbage collector is activated "when it feels like", and will
> > collect all garbage, or maybe just as much garbage as it is given
> time
> > to..., again depending on the implementation and the situation.
>
> This is only true for Jython and perhaps IronPython (I don't know
> how objects are managed there).
>
> In CPython, an object is GCed as soon as the reference count
> falls to zero.
>
> The Python garbage collector is only needed for situations where
> you've created circular references keeping a closed set of objects
> alive. The Python GC is run every now and then or explicitly
> by calling gc.collect().
That could change the day someone decides to re-write CPython with
better multi-threaded performance.
To be strict, reference counting is a garbage collecting method itself,
although it needs to be complemented with a circular references
detector.
It's also a garbage collecting method that generaly performs poorly in
multi-threaded environments, thus we might want to replace it
eventually.
One should not write code that depends on the garbage collector. Even
with reference counting, it's not 100% deterministic since reference
counting won't free circular referenced objects.
Remeber: garbage collecting is about freeing unused memory, not other
resources.
More information about the DB-SIG
mailing list