Three (3) List classes to prevent memory leaks

Here are two template classes and one normal class designed to prevent memory leaks.

CMyList (template)
This class is a wrapper for the CList MFC template class. It adds extra functionality and allows its member items to serialise themselves (important for schema versioning).

CMyTypedPtrList (template) my personal favourate
This class is a wrapper for the CTypedPtrList MFC template class. The items pointed to will be properly deleted thus causing no memory leaks.

CMyObList (standard class)
This class is a wrapper for the CObList MFC class. The items pointed to will be properly deleted thus causing no memory leaks.

Downloads

Download demo project - 9 Kb
Download source - 3 Kb

History



Comments

  • Serialization update

    Posted by Legacy on 07/20/1999 12:00am

    Originally posted by: Simon Hughes

    The following additional code allows for proper serialization.
    
    

    Add the following to the CMyTypedPtrList template
    void Serialize(CArchive &ar)
    {
    if(ar.IsLoading())
    RemoveAll();
    CTypedPtrList<CObList, TYPE*>::Serialize(ar);
    }

    Add the following to the CMyObList class.
    void Serialize(CArchive &ar)
    {
    if(ar.IsLoading())
    RemoveAll();
    CObList::Serialize(ar);
    }

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Webinar on September 23, 2014, 2 p.m. ET / 11 a.m. PT Mobile commerce presents an array of opportunities for any business -- from connecting with your customers through mobile apps to enriching operations with mobile enterprise solutions. Join guest speaker, Michael Facemire, Forrester Research, Inc. Principal Analyst, as he discusses the new demands of mobile engagement and how application program interfaces (APIs) play a crucial role. Check out this upcoming webinar to learn about the new set of …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds