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

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds