none
Memory Leak in CString (C++) RRS feed

  • Question

  •   Hi ..   I found memory leak in CString (C++) . RUN FOLLOWING CODE ON YOUR MACHINE IT GIVES U BETTER IDEA.

    CMemoryState msOld, msNew, msDif;
     
     //Obtains a snapshot or checkpoint of the current memory state.
     msOld.Checkpoint();

     CString szEmail = "bhaumik_4u@yahoo.co.in";

     msOld.DumpAllObjectsSince();
     //Obtains a snapshot or checkpoint of the current memory state.
     msNew.Checkpoint();

     //Check Difference - It should be 0 but it returns nonzero means
     //there is a leak.
     if( msDif.Difference( msOld, msNew ) ){
            TRACE( "Memory leaked!\n" );
        }else{
      TRACE( "No Memory leaked!\n" );
     }

     //Prints memory allocation statistics for a CMemoryState object
     msDif.DumpStatistics();

    thanks
    bhaumik_4u@yahoo.co.in

    Wednesday, June 4, 2008 10:28 AM

Answers

  • That is not a valid report, because your string object did not go out of scope.
    Microsoft MVP VC++ | www.mariusbancila.ro | www.mariusbancila.ro/blog
    Wednesday, June 4, 2008 1:54 PM

All replies

  • Does the leak occur if the string is enclosed in a short “{}” block:


    . . .

    {

        CString szEmail = "bhaumik_4u@yahoo.co.in"

    }

    . . .


    i.e. if the string is destroyed before checking for leaks?

    Wednesday, June 4, 2008 11:25 AM
  • That is not a valid report, because your string object did not go out of scope.
    Microsoft MVP VC++ | www.mariusbancila.ro | www.mariusbancila.ro/blog
    Wednesday, June 4, 2008 1:54 PM