Jump to content
  • Advertisement
Sign in to follow this  
shane1985

File Input Memory Problem

This topic is 5126 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'm writing code to load my map files, and when I exit the program, I get about 150 2kb memory leaks in the debug window. FILE * map; map = fopen(filename.c_str(), "rb"); fscanf(map, "%d", &numtiles); BYTE * image = new BYTE[32*32*3*numtiles]; // when I comment this out, I get no memory leaks fread(image, sizeof(BYTE), 32*32*3*numtiles, map); // do some other stuff delete [] image; fclose(map); How do I remove these memory leaks? Thanks! -Shane

Share this post


Link to post
Share on other sites
Advertisement
I don't see a memory leak in that code. Furthermore, I can't imagine how calling fread could possibly cause a memory leak. The problem probably lies somewhere else.

However, there is a small problem. fscanf and fread generally don't mix. fscanf parses the input (skipping spaces and stuff) and fread doesn't. fscanf is used for reading text and fread is used for reading binary data.

Share this post


Link to post
Share on other sites
Yeah, I don't understand either - I mean, I delete the image data after I'm done too.

I get about 150 of these:
{983} normal block at 0x0548CB48, 2000 bytes long.
Data: < I D 8D B> 00 C7 49 00 00 00 C4 44 00 00 38 44 00 00 00 42

Share this post


Link to post
Share on other sites
That code does seem sound. As already mentioned, it is possible that the memory leak exists elsewhere--dealing with memory can cause some pretty weirdo problems, so, check other parts of your code. Once I had a memory violation in sprintf (or some similar function). I couldn't figure it out...The code looked fine, but the compiler told me it was there. Well, out of desperation, I decided to check some code around it. The problem was with some pointers that I had setup before the code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!