[Python-3000] Use Py_CLEAR only
"Martin v. Löwis"
martin at v.loewis.de
Sun Apr 23 23:11:34 CEST 2006
Greg Ewing wrote:
>> Both should be optimized away by the compiler.
>
> How? I don't see how the compiler can know either of
> those things.
As you then discussed: it can do that for local variables
(it might even *warn* about the redundant assignment, though).
OTOH, for local variables, it might be of least interest:
it's usually pretty clear whether they will be accessed
again or not.
For global variables, I'm completely in favour of releasing
them through Py_CLEAR always.
For pointer that live on the heap, Py_[X]DECREF is usually
done because either
a) the memory block containing the pointer is about to be
released (e.g. when a tuple is deallocated), or
b) the pointer is about to be changed to point to something
else (e.g. a setitem operation)
In either case, there isn't much value to clearing the
pointer: In case b), the value will change right away again,
and in case a), if anybody still has a pointer to the block,
we are in trouble, and clearing the pointer likely doesn't
help in finding the trouble.
Regards,
Martin
More information about the Python-3000
mailing list