Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kirkd

fstream memory leaks??

This topic is 5719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!