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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

Most Popular Programming Stories

More for Developers

RSS Feeds