Delete in c++ program is not freeing up memory [cl

2019-03-06 23:25发布

问题:

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

回答1:

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.