[Python-Dev] Overwriting objects before deallocating them

David Abrahams David Abrahams" <david.abrahams@rcn.com
Fri, 24 May 2002 12:17:59 -0400


From: "Guido van Rossum" <guido@python.org>


> [Tim]
> > I'm not sure why, but there's a widespread intransigent belief that
> > it's somehow purer to say "del" for freeing memory that happened to
> > hold an object.
>
> I'm the origin of this convention; it was part of Python 0.0.
> Switching from [m]alloc/free to new/del was *not* to differentiate
> between mere blobs of memory and objects; it was to indicate that
> these macros and functions were a layer on top of malloc/free.
> (Originally, they merely changed the signature around a bit.)
>
> The new/del names are partly borrowed from C++, where new and delete
> are the memory (de)allocation operators as well as the object
> (de)allocation operators.

Yes, but in C++, when they're used as operators, they *always* do object
construction/destruction as well. In fact, in some forms (placement new)
its possible to get just the construction/destruction behavior without any
allocation/deallocation. I think Tim is on the right track.

-Dave