I created an object which has few integer variables, and one char memory block say which is allocated with memory of 300-500 bytes as its members . After that this object was pushed in to vector by one thread, and then another thread which is running parallel will swap with one empty vector and start processing the vector which contains the object, after processing I used to delete the char block used in object and also finalized the object and deletd the object also. But it seems the memory was not freeing up. I ran this block of code with valgrind tool it doesn't show any leak. Please help me with the solution
Asked
Active
Viewed 2,742 times
-2
-
4If you ran it in valgrind and it didn't show you any memory leak then why do you *assume* you are leaking memory? What is the basis of this assumption? BTW, `delete` does not free any memory it marks the memory block free for re-utilization. – Alok Save Jan 27 '13 at 06:44
-
Once after the completing the execution of program, memory used by that application doesnt comes down. i.e., while execution the program by running top command I found that the application written by me using 500 MB of RAM once after execution it should come down rigth, but it is not doing so – balu Jan 27 '13 at 06:47
-
Seems you are using the task manager to track memory usage. It doesn't really serve the purpose & not the right way to track memory leaks.If valgrind reports no memory leaks be assured you have none. – Alok Save Jan 27 '13 at 06:49
-
possible duplicate of [How do malloc() and free() work?](http://stackoverflow.com/questions/1119134/how-do-malloc-and-free-work) – talonmies Jan 27 '13 at 09:29
1 Answers
3
But it seems the memory was not freeing up.
How are you determining that exactly? I assume incorrectly. Calling delete whatever
marks that memory as deallocated and free for future use. The language doesn't specify exactly what that means. Your OS is better at managing memory than you are. It isn't forced to, for example, ensure that whatever tool (task manager?) you are using to measure memory usage now sees X more free bytes.
The memory you were using is now free to be allocated again. That's what you need to be concerned with, let the OS's memory manager worry about the details.

Ed S.
- 122,712
- 22
- 185
- 265