Shitiz Bansal wrote:
No, this list is not a linked list.
Since mu original code is rather huge, I am presenting
the relevant snippet.
queue=[]
def genpassenger(num,destination,queue=queue):
    for i in range(num):
        newpass=passenger(destination)
        queue.append(newpass)
        newpass.start()
class passenger(threading.Thread):
        def __init__
        <snip>
        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
part

In the code you have shown, I don't see any need for the queue. Just create the thread and start it. I don't think you have to keep a reference to it. I'm not sure, but I think the thread will be garbage collected when it completes. (Can anyone else confirm this?)


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
list)).

Yes. When there is no remaining reference to an item it is garbage collected.

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.

This is not needed. When a class is GCed then everything it references will also be GCed, unless something else still retains a reference to it.


Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to