title: How to free memory from a list of classes
body: <p>Say I have two classes created work and workItem.</p>
  
  <pre><code>        CWorker *work = new CWorker();
          CWorkItem *workItem = new CWorkItem();
  </code></pre>
  
  <p>The work class has a public list m_WorkList and I add the work item to it.</p>
  
  <pre><code>work-&gt;m_WorkList.push_back(workItem);
  </code></pre>
  
  <p>If I just delete work </p>
  
  <pre><code>if(work != NULL)
  delete work;
  </code></pre>
  
  <p>Do I need to loop through the list in the destructor like the following? Any better way to do this? Could I use clear instead?</p>
  
  <pre><code>while(m_WorkList.size())
  {
      CWorkItem *workItem = m_WorkList.front();
      m_WorkList.pop_front();
      if(workItem)
          delete workItem;
  }
  </code></pre>