Python language problem

ripley ripleyfu at gmail.com
Wed Jun 7 07:37:54 EDT 2006


Laszlo Nagy wrote:
> You must undestand that 'a' and 'b' are names. You can only delete
> names, not objects. Objects are freed by the garbage collector,
> automatically. Probably you used to write programs in C or Pascal or
> other languages with pointers. In Python, there are no pointers, just
> references and you cannot free an object. You can only delete the
> references to it. The good question is: why would you like to free an
> object manually? The garbage collector will do it for you automatically,
> when the object has no more references. (Well, cyclic references are
> also garbage collected but not immediately.)
>
> If you need to handle resources, you can still use the try-finally
> statement. Like in:
>
> f = file('example.txt','r')
> try:
> s = f.read()
> finally:
> f.close() # The resource is freed. But the object that was used to
> access the resource, may not be freed here....
>
> Regards,
>
> Laszlo

Thanks for your so detailed explain, I think I know you, But my Engish
is not enough
to explain.

I create same object in Tree, I want to update Tree, when I need to
delete subtree.
If where no references, I can't do that. some thing like blow:
for i in list:
   del i
>From that code, I can't update list anymore.




More information about the Python-list mailing list