title: Destructors and Malloc'd Members
body: <p>Lets say, for example, that I have a class that requires the use of some old C stuff (like pthreads or something), so for one reason or another, I've ended up with a malloc() call in my constructor, like so:</p>
  
  <pre><code>class Foo
  {
    public:
      Foo()
      {
        someMutex = malloc(sizeof(pthread_mutex_t));
        pthread_mutex_init(someMutex);
        someString = new string("yay string!");
      }
  
    private:
      pthread_mutex_t * someMutex;
      string * someString;
  }
  </code></pre>
  
  <p>It seems like there is a lot of misinformation about destructors out there. I keep seeing examples of explicitly defined destructors calling <code>delete</code> on pointer based members, but I also keep reading that I don't need to explicitly define a destructor for a class to manage memory; all I need a destructor for are things like file handle cleanups and the like.</p>
  
  <p>Thus leads to my question then: Even though <code>someMutex</code> was allocated with <code>malloc</code> and not the C++ <code>new</code> command, will the implicitly defined destructor still take care of it, or do I have to do it?</p>
  
  <p>Also, lets just settle another question of mine, since its so closely related. In the class above, do I need to explicitly define a destructor in order to call <code>delete</code> on <code>someString</code>, or is that taken care of for me?</p>