[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: The great destroy mystery.
From:       Richard Garand <richard () garandnet ! net>
Date:       2003-08-08 0:29:50
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On August 7, 2003 06:04 pm, 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?  I can't
> find any consistent info on this. The C++ FAQ says that such objects are
> "automagically" destroyed when the parent object is destroyed. Elsewhere
> in the same FAQ, it says that one _must_ call delete for every new. ??

That's wrong. Sort of. Dynamic memory is never freed automagically by C++ 
itself; however, since this is an excellent way to create memory leaks, many 
people write code that does do this in one way or another; QObjects will 
delete all their children, and you can get smart pointer classes that will 
delete the pointer when no one is using it anymore. In most cases, you have 
to delete everything you allocate.

> "If the pointer you're deleting is zero, nothing will happen. For this
> reason, people often recommend setting a pointer to zero immediately
> after you delete it, to prevent deleting it twice. Deleting an object
> more than once is definitely a bad thing to do, and will cause problems."

Deleting an object more than once means deleting the same pointer twice 
without setting it to zero. This should be avoided if possible; I've heard 
that some or all of the BSDs can detect this and prevent problems, but don't 
rely on that.
- -- 
Richard Garand  --  http://www.garandnet.net
I love mankind ... It's people I hate.
                -- Schulz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/Mu8CeCvRFgufeeYRAtqfAKDjWhgR1WjNgX5+SvwfFYPcT4iDkQCfd3pk
limUFRQQXE502m73P3j5nvI=
=th+S
-----END PGP SIGNATURE-----

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic