fstream memory leaks??

Started by
6 comments, last by kirkd 21 years, 3 months ago
I have some VERY simple code which is causing an apparent memory leak. I've been using _CrtMemCheckpoint() and _CrtMemDifference(,,) to monitor the allocation status and it reports a leak in the following situation:

void MemoryLeakTesting()
{

   _CrtMemState before, after, diff;
   _CrtMemCheckpoint(&before);

   LoadDataSet(parameters...);

   _CrtMemCheckpoint(&after);
   if ( _CrtMemDifference(&diff, &before, &after) )
        _CrtMemDumpStatistics( &diff );

}

bool LoadDataSet(parameters)
{
   fstream datafile;

   //lots of code commented out through here
   
   return true;
}
 
If I comment out the fstream line, no problem. But, as soon as the line is there, I fall into the DumpStatistics routine and get 73 bytes in 2 normal blocks. Any ideas?? -Kirk [edited by - KirkD on January 21, 2003 10:15:25 PM]
Advertisement
I do not know whether Microsoft uses this technique or not, but some libraries add memory to a pool of allocated memory rather than freeing it. This way, when it needs memory later it will just use the memory allocated earlier. Usually a limit on the memory pool though, so you could easily determine this by making the same call repeatedly an absurd number of times and see if this "memory leak" stops at some point.


Regards,
Drew Vogel
Regards,Drew Vogel
Other than the above, maybe it is the
//lots of code commented out through here
leaking.

[edited by - DerekSaw on January 21, 2003 7:44:43 PM]
"after many years of singularity, i'm still searching on the event horizon"
use <fstream> instead of <fstream.h> - it''s the standard
DerekSaw - I doubt that the commented lines are causing the memory leak because they are, well, commented.

Pete and dvogel, thanks for the leads. I''ll give ''em both a try.

-Kirk
DerekSaw - I doubt that the commented lines are causing the memory leak because they are, well, commented.

Pete and dvogel, thanks for the leads. I''ll give ''em both a try.

-Kirk
I changed to and included the namespace - no change.

I then made the function call 1000000 times and it never increased the size of the "leak." I suppose this suggests an allocation pool as dvogel suggested?

-Kirk
quote:Original post by Anonymous Poster
DerekSaw - I doubt that the commented lines are causing the memory leak because they are, well, commented.
-Kirk

LOL
"after many years of singularity, i'm still searching on the event horizon"

This topic is closed to new replies.

Advertisement