Newbie question about python garbage collection when keeping only a reference to an object's member
Emile van Sebille
emile at fenx.com
Fri Nov 12 17:20:17 EST 2010
On 11/12/2010 2:03 PM George Burdell said...
> My understanding is that any object which is not pointed to by any
> variable will be automatically deleted. What if I create a class
> object, but only keep a reference to one of its members, and not a
> reference to the object itself? What goes on internally in Python?
> Does Python retain the whole object, or does it just keep a copy of
> the referenced member?
>
> For example, if I have
>
> def myclass:
class myclass:
> def __init__(self):
> self.x = [1,2,3]
> self.y = [4,5,6]
> x = myclass().x
>
> This works, and I correctly get x = [1,2,3]. But what happened to the
> myclass() object initially created, and the member "y"?
Garbage collect(ed|able)
It only existed (was referenceable) while instantiated and can be gc'd
one no longer referenced.
Emile
More information about the Python-list
mailing list