Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!att!ulysses!andante!alice!shopiro From: shopiro@alice.UUCP (Jonathan Shopiro) Newsgroups: comp.lang.c++ Subject: Re: deallocating an array of objects Summary: Deleting null is harmless Message-ID: <9517@alice.UUCP> Date: 21 Jun 89 02:44:19 GMT References: <2735@ssc-vax.UUCP> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 45 In article <2735@ssc-vax.UUCP>, dmg@ssc-vax.UUCP (David Geary) writes: > > In article <9500@alice.UUCP>, Jonathan Shopiro writes: > + In article <1245@cadillac.CAD.MCC.COM>, rpj@redcloud.cad.mcc.com (Rich Johns) writes: > ... > + - for (int i = 0; i < 100; i++) { > + - delete fooArray[i]; > + - } > > + This deletes the pointed-to Foos (and they better be there to delete) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > If the pointed-to Foos are not there, and each element of FooArray > is NULL, will > > delete fooArray[i]; > > do any harm? I was under the impression that delete, when applied > to NULL does nothing. Quite so. In the original example, they weren't null, they were uninitialized. I think it is unfortunate that the language guarantees that delete can be applied to null harmlessly (the compiler has to generate code to check for null every time) and I think it is bad form to apply delete to null pointers. b o r i n g b o r i n g -- Jonathan Shopiro AT&T Bell Laboratories, Warren, NJ 07060-0908 research!shopiro (201) 580-4229