[Tutor] Is there a heaven for old instances ?

dman dsh8290@rit.edu
Sun, 9 Dec 2001 21:48:03 -0500

On Sun, Dec 09, 2001 at 07:43:42PM +0200, Jean Montambeault wrote:
|     I wonder :
|         when I re-assing a variable like this :
|             a=3
|             a=4
|             a="Couldn't you make up you mind ?"
|     the old values (e.g. 3 and 4) are destroyed or so I read. (BTW is that
| what "garbage collection" does ?).

Yes.  It just so happens that CPython creates the integers -1..99 at
startup because they are so commonly used, so in this case it doesn't
go away.  (I don't know if Jython does this or not)  Aside from this
special case, you are correct.

|     Now if I create and instance, let's say this way:
|         instance1=Button(somewhere, lots of options or none)
|     and then for some (stupid?) reason I go:
|         instance1=Button(somewhere_else_or_not, new options_maybe)
|     what happens to the first instance which is much more complex than a
| simple variable ?

The same thing.  If there are no more references to the first Button
instance, it is destroyed.  If you have stuck it in a frame or kept a
reference somewhere, it is not destroyed, you just don't have a
reference in the local scope.



If your life is a hard drive,
Christ can be your backup.