By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

deleting a parameter's name as it is passed to a function

P: n/a
Hi,

I think it would be useful to delete a name of a parameter object as
the object is passed to a function:

dosomestuff(del a)

instead of

dosomestuff(a)
del a

The idea is to garbage collect the object as soon as possible, and this
may be sooner than when dosomestuff returns.

Amir

Oct 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Amir Michail" <am******@gmail.com> writes:
The idea is to garbage collect the object as soon as possible, and this
may be sooner than when dosomestuff returns.


If it's a parameter to dosomestuff, then there's still a reference
until dosomestuff returns. Simply getting rid of the name only frees
a dictionary entry.
Oct 15 '05 #2

P: n/a
Paul Rubin wrote:
"Amir Michail" <am******@gmail.com> writes:
The idea is to garbage collect the object as soon as possible, and this
may be sooner than when dosomestuff returns.


If it's a parameter to dosomestuff, then there's still a reference
until dosomestuff returns. Simply getting rid of the name only frees
a dictionary entry.


But dosomestuff can get rid of its reference before it returns (perhaps
it has a lot more to do before it returns and so you would want to
garbage collect the parameter object as soon as possible).

Amir

Oct 15 '05 #3

P: n/a
On Fri, 14 Oct 2005 17:40:48 -0700, Amir Michail wrote:
Hi,

I think it would be useful to delete a name of a parameter object as
the object is passed to a function:

dosomestuff(del a)
That's a horrible syntax. It would require Python to be completely
re-designed to allow statements where expressions are allowed, and it
isn't even clear what your syntax means. It looks like it means "delete
object a, and then call dosomestuff on the result returned by del".

instead of

dosomestuff(a)
del a
That is lovely and clear.
The idea is to garbage collect the object as soon as possible, and this
may be sooner than when dosomestuff returns.


What difference does that make? Why do you care when object a is garbage
collected?
--
Steven.

Oct 15 '05 #4

P: n/a
"Amir Michail" <am******@gmail.com> writes:
But dosomestuff can get rid of its reference before it returns (perhaps
it has a lot more to do before it returns and so you would want to
garbage collect the parameter object as soon as possible).


That would be so rare and weird that your best bet is to just pass a
boxed object in the odd circumstances where it will make any
difference. Instead of dosomestuff(x), say dosomestuff([x]). Then
dosomestuff can mutate the list:

def dosomestuff(xl):
x = xl.pop()
... do stuff with x ...
x = None # free the reference
... more stuff...
Oct 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.