Delete in c++ program is not freeing up memory [closed]

我只是一个虾纸丫 提交于 2019-11-28 13:56:10

问题


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.



来源:https://stackoverflow.com/questions/14545095/delete-in-c-program-is-not-freeing-up-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!