From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,345a8b767542016e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-15 07:58:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.online.be!zur.uu.net!ash.uu.net!spool0900.news.uu.net!reader0900.news.uu.net!not-for-mail Message-ID: <3C921A81.9060708@mail.com> Date: Fri, 15 Mar 2002 11:00:01 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:0.9.9) Gecko/20020311 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: memory leakages with Ada? References: <3c90af1e@news.starhub.net.sg> <3c91bfa3.1987537@news.demon.co.uk> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Cache-Post-Path: master.nyc.kbcfp.com!unknown@mosquito.nyc.kbcfp.com X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1016207883 reader0.ash.ops.us.uu.net 25872 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:21289 Date: 2002-03-15T11:00:01-05:00 List-Id: John McCabe wrote: > One of the things I've found recently, since starting to use C++ more, > is that Ada.UncheckedDeallocation is so much nicer than 'delete' as it > returns you a nice, null pointer! 'delete' in C++ appears to remove > the allocated block, but leave your pointer pointing to where it used > to be! If I'm not mistaken (not really knowing Ada), Ada.UncheckedDeallocation is a generic procedure which must be instantiated for each access type you are interested in freeing. So if you want that behavior in C++, you should have no qualms about adding your own procedure in the same way. template void unchecked_deallocation(T *&p) { delete p; p = 0; } The counter argument is that dangling pointers are a problem where they have been copied into other data structures, so nulling one particular variable which is holding the pointer isn't all that useful. Also, freeing memory tends to happen as part of the process of cleaning up a data structure which is itself about to disappear, so again nulling the pointer isn't going to accomplish much.