From kde-devel Fri Aug 08 00:36:03 2003 From: Thiago Macieira Date: Fri, 08 Aug 2003 00:36:03 +0000 To: kde-devel Subject: Re: The great destroy mystery. X-MARC-Message: https://marc.info/?l=kde-devel&m=106030310324947 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============19194856180421405==" --===============19194856180421405== Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Boundary-02=_zBvM/+IJf8kr6ob"; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --Boundary-02=_zBvM/+IJf8kr6ob Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Gary Cramblitt wrote: >In my object destructor, do I need to explicitly destroy object pointers >declared as member variables and initialized with _new_ or not?=20 Yes. For everything that you new, you must delete and exactly only once. >I can't=20 >find any consistent info on this. The C++ FAQ says that such objects are >"automagically" destroyed when the parent object is destroyed. It was not referring to objects allocated in the heap with new. >But the FAQ says that calling delete more than once on the same object >won't hurt. "Thinking in C++" is strangely mute about "automagic" >destruction. Deleting twice the same object is definetely wrong. And will cause trouble= =20 most of the times. That's why setting it to 0 is a good recommendation if t= he=20 pointer is still going to be accessed. >There was a thread in this list about a month ago that asked the same >question, but once again, there were conflicting answers. So here's the answer: for every new, there must be exactly one delete. It's= =20 like malloc: there must be one free. =2D-=20 Thiago Macieira - Registered Linux user #65028 thiagom@mail.com =20 ICQ UIN: 1967141 PGP/GPG: 0x6EF45358; fingerprint: E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358 --Boundary-02=_zBvM/+IJf8kr6ob Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQA/MvBzM/XwBW70U1gRAr3/AKCnMfbSzxIWqXtRfpzPNHXTn8dRggCgyKTq 4MFHaO83d56Vg1aJKYlLLmg= =cu5/ -----END PGP SIGNATURE----- --Boundary-02=_zBvM/+IJf8kr6ob-- --===============19194856180421405== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --===============19194856180421405==--