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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds