home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!corton!seti!goudurix.inria.fr!edelson
- From: daniel.edelson@inria.fr (Daniel R. Edelson)
- Newsgroups: comp.lang.c++
- Subject: Re: delete versus delete[] (was Re: leakmeister)
- Message-ID: <4009@seti.UUCP>
- Date: 21 Jul 92 08:18:49 GMT
- References: <l6hmegINNfva@male.EBay.Sun.COM> <1992Jul18.200210.4119@taumet.com> <1992Jul19.162429.4307@usenet.ins.cwru.edu>
- Sender: news@seti.UUCP
- Reply-To: Daniel R. Edelson <daniel.edelson@inria.fr>
- Organization: INRIA -- Institut National de Recherche en Informatique et Automatique -- Rocquencourt, France
- Lines: 21
-
- In article <1992Jul19.162429.4307@usenet.ins.cwru.edu>, aa753@cleveland.Freenet.Edu (Bob Jarvis) writes:
- |>
- |> This should work correctly. The only time that the 'delete []' syntax is
- |> required is if you have a dynamically-allocated array of class instances
- |> which have a destructor you want to have invoked for each class instance
- |> in the array.
-
- Nonetheless, the effect of deleting an array with the plain delete syntax
- is undefined. The definition of such "undefined behavior" is "an error that
- the compiler is not required to diagnose."
-
- It is not difficult to think of times when this can
- lead to problems, even for a class that doesn't have a
- destructor. Suppose that the class overloads new and
- delete to use a customized memory allocator. Allocating
- the array with `new T [x]' will call the global operator
- new and obtain memory from the standard place, whereas
- deleting it without the array syntax will return the memory
- to the custom allocator. This is not what you want to happen.
-
- daniel.edelson@inria.fr
-