Author Topic: [C/C++] malloc() and memset() issues  (Read 5576 times)

Offline CaptainCPS

  • Administrator
  • *****
  • Posts: 1520
  • Karma: +126/-0
  • FB Alpha Team
    • CaptainCPS's Home
[C/C++] malloc() and memset() issues
« on: February 24, 2010, 10:51:02 am »
I been trying to properly use malloc() / memset() functions to allocate memory and free() after I finish using it in my personal application and C/C++ projects but memory doesn't seem to be properly free and Im going crazy! xD

I currently doing test with a program that loads a text file, stores its content line by line into a temporary string array then finally copy each element in the string array (line string) to a structure array and put it on a Listbox.

After using malloc() / memset() I made sure I put a free() at the end so it's supposed to be free, but when I verify the program in Task Manager, every time I do the text file loading it consumes 4KB more, and more. The text file is 2KB so I guess the temporary Strings and the structure's memory is never freed.

If someone has a very good example on how to allocate and free memory after using it I will really appreciate it ^^ If I can implement this in my applications and projects they will be more effective and avoid memory leaks.

SeeYaa!
 :biggrin:

Offline kenshiro

  • Expert
  • *****
  • Posts: 145
  • Karma: +21/-0
Re: [C/C++] malloc() and memset() issues
« Reply #1 on: February 26, 2010, 04:04:29 pm »
Can you post the code where you have the actual memory leak please? BTW, maybe it's a dumb idea but did you close the file stream (fclose(yourfile))? lol

Kiss,

Offline CaptainCPS

  • Administrator
  • *****
  • Posts: 1520
  • Karma: +126/-0
  • FB Alpha Team
    • CaptainCPS's Home
Re: [C/C++] malloc() and memset() issues
« Reply #2 on: March 04, 2010, 08:08:49 am »
Can you post the code where you have the actual memory leak please? BTW, maybe it's a dumb idea but did you close the file stream (fclose(yourfile))? lol

Kiss,

Sorry I didn't reply sooner, I've been very busy with university and doing a new system install (a hacked system xD) and I haven't been working with the code for now, but as soon as I finish working with the system instalation I will post the code so you can help me better ^^

ThanX for your time man! Take Care!

SeeYaa!
 :biggrin:

Offline Romhack

  • Expert
  • *****
  • Posts: 90
  • Karma: +49/-0
Re: [C/C++] malloc() and memset() issues
« Reply #3 on: March 08, 2010, 07:46:43 pm »
Are you using "fclose()" too? if not, it seems that OS is using cache with 1 memory page (4KB = 1 page)...
Or free() isn't marking pages allocated as free...
And listbox consumes quite memory too.

Well, I guess...
Sorry, my english isn't good... :(