[Pythonmac-SIG] Automatic disposing of toolbox objects

Jack Jansen jack@oratrix.nl
Sun, 02 Jan 2000 00:30:50 +0100


Currently some toolbox objects (like windows) are automatically
disposed when the Python object loses its last reference, while others 
(like resources/handles) are not, and have to be manually disposed.

The reasons for this are mainly historic, although there is some
practical reason too: the Res.Resource object can be a handle or a
resource, and these have to be disposed of in different
ways. Moreover, often you get passed a handle by some other part of
the system that isn't yours, so you definitely shouldn't dispose it.

Windows are different: as you usually create them yourself disposing
them upon cleanup of the Python object is usually fine.

But, of course, I'm now finally running into problems with this: since 
I've been adding all this appearance stuff it is pretty possible to
get a Python object referring to, say, a List that is part of a list
control. Disposing this list upon release of the Python object will
come as a surprise (read: bus error:-) to the Control Manager.

I can hack my way around this (of course:-), but this whole automatic
disposal vs. manual disposal mess has bothered me for years, so maybe
it's time to do something about it. So please shine your light on the
following ideas (and, of course, feel free to come up with better
ones):

- Add a "disposer" field to all the toolbox objects. This is a (C)
routine to be called on the underlying object or NULL. There would be
a Python call on the object to allow you to set/reset (or, in case of
resources, set-to-DisposeHandle/set-to-ReleaseResource/reset) the
field. The toolbox modules would make an educated guess as to what to
initialize the field to, but you could always override it from Python.

- Take the whole idea a bit further, notice that all the toolbox
PyObjects are the same in C (a struct with a handle), and create an
API that allows for in-place(!) modification of the PyObject object
type. Then we'd have List objects (not LDispose()d on release of the
Python object) and ManagedList objects (which are LDisposed),
etc. Moreover, we could solve the Handle/Resource problem, more easily 
convert Handles to Lists/Icons/etc. The tricky bit here is that the
PyObject type field has to be modified, and while I can't think of any 
obvious problems with this I'm not sure about it.
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm