Is it worth setting pointers to NULL in a destructor?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-06-17T08:23:47Z Indexed on 2010/06/17 8:33 UTC
Read the original article Hit count: 115

Filed under:

Imagine I have a class that allocates memory (forget about smart pointers for now):

class Foo
{
public:
  Foo() : bar(new Bar)
  {
  }

  ~Foo()
  {
    delete bar;
  }

  void doSomething()
  {
    bar->doSomething();
  }

private:
  Bar* bar;
};

As well as deleting the objects in the destructor is it also worth setting them to NULL?

I'm assuming that setting the pointer to NULL in the destructor of the example above is a waste of time.

© Stack Overflow or respective owner

Related posts about c++