freeing objects

Terry Reedy tjreedy at udel.edu
Fri Jun 20 12:02:50 EDT 2003


"delphiro" <delphiro at zonnet.nl> wrote in message
news:mailman.1056107842.11261.python-list at python.org...
> Hi everyone,
>
> I am writing an application where I use Chaco for the excellent
graphical output and now I have a question about creating / freeing
objects.
>
> I use this code to create and assign a chaco-object (a 'vertical')
to my dialog:
>
> self.plotitem = PlotCanvas( pv1, PlotTitle( 'Soilstress in vertical
..' ), plot_type = 'rangebar', axis_index = x_ax, axis = y_ax )
>
> now the user has the possibility to change the view to another
'vertical' so self.plotitem should be assigned to another PlotCanvas
and the old one should disappear.
>
> What is the correct way to do this?
>
> should I 'free' self.plotitem before assigning a new PlotCanvas to
self.plotitem and if so, how do you 'free' objects in Python?

'Deleting' an item actually and only deletes the association between
the handle (name, attribute, or collection slot) and the object.
Assigning a new object to a handle implicitly does a delete with
respect to the old association.  For this much, an explicit delete
would be redundant.

When the association or reference count goes to 0, the interpreter
*may* do some sort of cleanup, including calling its __delete__
method.  Whether and when it *does* so can and does depend on the
implementation.  If you need to make explicitly sure cleanup is done,
give the object a close method and call it before breaking your link
to it.

Terry J. Reedy






More information about the Python-list mailing list