On 21 Nov 2003 at 14:15, Brian Kelley wrote: [garbage collection vs ref counting]
> I always get this particular terminology jumbled when it comes to > python. There are two things going on, reference counting and garbage > collection. Just to see if I have this straight: > > When a storage goes out of scope the current version of C Python > finalizes the storage object relatively quickly. Immediately. It happens inline. > ... It is related to garbage > collection in that when an object's reference count goes to zero, it can > be finalized and also it can be garbage collected. Not exactly. GC is for collecting unreachable objects which still have ref counts > 0. Usually that's a container where the contained reference the container, but the container has gone out of scope. > The point is that python doesn't document when to finalize or garbage > collect and one technically shouldn't make assumptions about when this > is going to happen, just that it will. I've been raked over the coals > on this particular subject :) Snort. If you rely on GC, you can't even rely on "it will". Personally, if I can't create cycle-less programs, I use weakrefs. > The following pythonic idiom doesn't work > on storage objects: > > storage = metakit.storage(...) > try: > # do some work on the storage > finally: > # ensure that the storage is closed > storage.close() > > So one has to trust the implementation of python to handle the details. > For all intents and purposes CPython 2.3 will close down the storage for > you 'very soon' after the storage goes out of scope (or the refcount > goes to 0). You mileage may very if you are using jython for instance. storage = None works fine there. GC will never be invoked in this case (there has to be a container involved). In jython you'd still need to say storage = None for GC to realize it was collectable. -- Gordon _______________________________________________ metakit mailing list - [EMAIL PROTECTED] http://www.equi4.com/mailman/listinfo/metakit
