Miscellaneous > Programming

[C/C++] malloc() and memset() issues

(1/1)

CaptainCPS:
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:

kenshiro:
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,

CaptainCPS:

--- Quote from: kenshiro 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,

--- End quote ---

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:

Romhack:
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... :(

Navigation

[0] Message Index

Go to full version