When (and why) to use del?
Slaunger
Slaunger at gmail.com
Tue Dec 9 11:45:37 EST 2008
On 9 Dec., 17:35, Albert Hopkins <mar... at letterboxes.org> wrote:
> I'm looking at a person's code and I see a lot of stuff like this:
>
> def myfunction():
> # do some stuff stuff
> my_string = function_that_returns_string()
> # do some stuff with my_string
> del my_string
> # do some other stuff
> return
>
> and also
>
> def otherfunction():
> try:
> # some stuff
> except SomeException, e:
> # more stuff
> del e
> return
>
> I think this looks ugly, but also does it not hurt performance by
> preempting the gc? My feeling is that this is a misuse of 'del'. Am I
> wrong? Is there any advantage of doing the above?
I agree with you. In my mind there is no reason for such kinds of
deletes. The code seems to have been made by a person who úsually
programs in a language which does not have a garbage collector. I do
not know if it has any noticeable impact on the performance.
-- Slaunger
More information about the Python-list
mailing list