dynamic modules

Jeff Shannon jeff at ccvcorp.com
Wed Dec 19 12:57:11 EST 2001

Werner Schiendl wrote:

> Hi,
> you can create a type (a class) instead of a plain module.
> When the reference count drops to zero, the instance will then be deleted.
> It is probably possibly to create a singleton class, that always returns one
> single instance if there is one instead of creating a new one every time.
> But I never tried that.
> hth
> Werner

ActiveState's Python cookbook has a Singleton recipe at


and also the even-better Borg pattern from Alex Martelli:


Though, if the intent is to be able to clear out a large chunk of memory, I'm
not positive that either of these patterns will work.  In both cases, even if
you delete all the instances of your singleton/borg class, the class object
itself may still hold a reference to the shared data.  I suppose that, if you're
confident that you're done with it, perhaps you could delete the class object as
well....   something to look into, anyhow.

Jeff Shannon
Credit International

More information about the Python-list mailing list