[Tutor] How to delete a class instance

Shitiz Bansal 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.
def genpassenger(num,destination,queue=queue):
    for i in range(num):
class passenger(threading.Thread):
        def __init__
        def run:
            #do something
            delete itself

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
variables stored.


--- Kent Johnson <kent37 at tds.net> wrote:
> Shitiz Bansal wrote:
> > Hi,
> > How do i delete a class instance in a function
> running
> > within itself?
> > All the instances of the class are stored in a
> list,
> > and they need to be deleted after executing their
> > function.
> > However since the list is dynamic, there is no way
> to
> > 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.
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!

More information about the Tutor mailing list