[Tutor] Final de-allocation before the application exists
Alan Gauld
alan.gauld@blueyonder.co.uk
Tue Jul 22 16:48:02 2003
Hi,
> I cannot use destructors in my application because I have
> some static data in my application that is modified during
> the life cycle of the application.
More to the point Python does not really have destructors in
the sense that you seem to mean. Python controls the release
of resources not the programmer.
> I am allocating the resources and threads in my module
I'm not sue what you mean by this? I assume you are creating
objects and assigning variables to them? And those variables
have global scope? If so when the application exits Python will
garbage collect the objects to which they refer. The only
clear up you should need to do is close open files etc
(and Python actually does that too on exit, but its
considered polite for the programmer to do it expliicitly).
> I would like to de-allocate resources in the application
If you call the del() function you will decrement the
reference count on the object to effectively suggest to Python
that the resource can be garbage collected at a suitable time.
If the object has a __del__ method then when the garbage
collector eventually kicks in it will call the method.
Beyond that what do you perceive is needed?
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld