Forum Discussion

gvoots's avatar
12 years ago

Local Heap live counts after FormatMessage,LocalFree

I am running Allocation Profiler on the following code.( VS2003 C++ console app). 

options:  

    Check system memory allocations

    Check memory bounds

    Collect Stack info:  none

    Thread model: win32




int _tmain(int argc, _TCHAR* argv[])


{


    for(int i=0; i<1000; i++)


    {


          LPSTR msg = "dum de dum de dum.";


          LPVOID lpGrvBuf;


          FormatMessage( 


          FORMAT_MESSAGE_ALLOCATE_BUFFER | 


          FORMAT_MESSAGE_FROM_STRING | 


          FORMAT_MESSAGE_IGNORE_INSERTS,


         msg,


         0,


          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language


         (LPTSTR) &lpGrvBuf,


          0,


         NULL 


       );


       LocalFree(lpGrvBuf);


    }


     //pause - get AQTime results here


    std::cout << "Hit enter to continue";


    std::cin.get();


    return 0;


}




After running I get the following Class Data entry for LocalHeap:




Module Name                  |   Class Name   |  Namespace | Token | Finalizable


LOCALHEAPTEST.EXE  |  Local heap      |                          |       0    | False          |       



Total Created   |  Peak Created      |  Live Count      |     Total Size |   Peak Size   |   Live Size

           1000    |              1000       |         1000       |        0            |        0           |       0





My question is why is LiveCount 1000, when LocalFree is called after each FormatMessage call.  LocalAlloc is called from FormatMessage.



If I replace the FormatMessage call with:

               lpGrvBuf = LocalAlloc(LMEM_FIXED,20)

Then LiveCount is in fact zero.



My concern is whether the Live object count indicates  a resource drain of some kind, even though the associated memory sizes are zero?

(This is an excerpt from a  windows service, so it may run continuously with out being closed.)


        

2 Replies

  • aqAnt's avatar
    aqAnt
    SmartBear Alumni (Retired)


    Hello Geary,



    The behavior you described looks like an issue, so we will investigate it and let you know our results. Sorry for the inconvenience.


  • aqAnt's avatar
    aqAnt
    SmartBear Alumni (Retired)


    Hi All,



    I would like to notify you that we will fix the issue in the next AQtime update. We can also provide a patch for AQtime 8.0 if you contact us via our Contact Support form.