[Tutor] garbage collection/class question

richard kappler richkappler at gmail.com
Thu Jan 10 15:06:21 CET 2013


Class is still something I struggle with. I think I'm finally starting to
get my head wrapped around it, but the discussion in a different thread has
sparked a question. First, please check my understanding:
A class creates objects, it's like a template that allows me to create as
many copies as I want of the object but allows me to have slightly
different versions of the object by having different values for the
variables within the object, which I can set with arguments?
By using  __init__ (self) I instantiate a new copy of the object?

Whether the above is correct or not (and do please correct me/ tutor me),
my question is, if I create objects in a while True loop, do the objects
get garbage collected, ie. disappear when the loop returns to the beginning
and creates new versions of the objects?

Psuedo code example:

(presuming I have a class that creates a lemon, a lime and has a function
that operates on them called juice)

while True:
    lemon = yellow() # create a yellow object called lemon
    lime = green() # create a green object called lime
    drink = juice(lemon, lime) # operate on objects lemon and lime in a
function called juice resident in the class

So, using the above example, when the loop reaches the end and returns to
the beginning, new lemons and limes are created, yes? What happens to the
old ones? Or have I still got this completed boggled?

regards, RIchard

-- 

quando omni flunkus moritati
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130110/3d916c97/attachment-0001.html>


More information about the Tutor mailing list