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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-04 09:58:03 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!pd7cy2so!shaw.ca!sjc70.webusenet.com!news.webusenet.com!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada References: <8urxb.19482$sb4.18182@newsread2.news.pas.earthlink.net> <1792884.HtYz4Yv8lY@linux1.krischik.com> <1070466281.168920@master.nyc.kbcfp.com> <1070490862.478119@master.nyc.kbcfp.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 04 Dec 2003 12:43:31 -0500 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1070559778 198.96.223.163 (Thu, 04 Dec 2003 12:42:58 EST) NNTP-Posting-Date: Thu, 04 Dec 2003 12:42:58 EST Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:3129 Date: 2003-12-04T12:43:31-05:00 List-Id: Hyman Rosen wrote: > Robert I. Eachus wrote: > >> Ah, I think I get it. In C there are many occasions where a function >> will return a heap object, and it is up to the caller to free the >> memory. The returned value can be a copy of the original pointer, so >> in C it is relatively common to free a copy of the original heap >> pointer. That may be what is confusing Hyman. > > I'm confused about whether I'm confused :-) > > Anyway, C++ doesn't set a pointer variable to null when you free its > contents. > Since you should be doing this in destructors most of the time, it > doesn't matter, > because the pointer variable will very shortly not exist. Even in that case, you may still want to null the pointer. This can be helpful in debugging. An errant program may still try to use the object (now freed), and attempt to use the pointers contained within it. There is a better chance of the program failing (and getting fixed), if the pointers are now null. The reverse is true if the pointers are still there and are being used as buffers etc.. leading to strange and difficult to debug problems. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg