> On 6 Sep 2023, at 03:47, Daniel Walker <nickel...@gmail.com> wrote:
> 
> I use foo to instantiate another object:
> 
>     bar = Bar(foo)
> 
> bar is free to manipulate foo however it wants and even del it if necessary. 

foo is a reference to an object, it is not an object in its own right.
You can say that bar is free to not keep a reference to the object that foo 
points to.
So no, bar cannot manipulate foo.

> However, since the foo name is still around, those resources won't get 
> cleaned up even if bar is done with them.  The simple solution is
> 
>     bar = Bar(foo)
>     del foo
>     bar.do_stuff()

In depends on the scope that foo is in. If its a function then when you exit 
the function the ref-count
on the object that foo will be decremented for you.

Only if foo not going out of scope will you need the explitit del, for example 
in foo is defined at module level, etc.

I see no need for del to return anything, you already have the reference in foo.
The times that foo is dropped at module level are rare enough to not need 
special syntax.


Barry

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2GWNITBYV4GMPGWOHJVAN6L7LSQXXKXI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to