[Tutor] How to delete a class instance
shitizb at yahoo.com
Wed Mar 16 17:00:30 CET 2005
No, this list is not a linked list.
Since mu original code is rather huge, I am presenting
the relevant snippet.
for i in range(num):
genpassengers is called interactively by the user
.Also there can be multiple instances of genpassengers
running at the same time.
Now my questions are:
1) Generically , how do i accomplish the delete itself
2) If i used a linked list, does automatic memory
handling by python entail that delete itself is
automatically accomplished once i have readjusted the
pointers, since no further reference to the instance
remains.(Of course, if it doesnt i can get a reference
in the external code(in case of a doubly linked
3) How about making a destructor function (on lines
of c++) and deleting all the variables of the
class.Does it free all my memory or is there still
some memory being used, though the instance has no
--- Kent Johnson <kent37 at tds.net> wrote:
> Shitiz Bansal wrote:
> > Hi,
> > How do i delete a class instance in a function
> > within itself?
> > All the instances of the class are stored in a
> > and they need to be deleted after executing their
> > function.
> > However since the list is dynamic, there is no way
> > know the exact position of the instance within the
> > list.
> You have to do this from the caller, in code that
> has access to the list. There is no general way
> for an object to find out how it is being referenced
> in external code. Can you show some of the code
> that creates and uses the list? Does the code that
> calls the class know where the class is in the list?
> Is this the linked list you asked about before that
> is modified from two threads?
> > I tried del self to no avail.
> del self just removes the link between the name
> 'self' and the object it references.
> Tutor maillist - Tutor at python.org
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
More information about the Tutor