Memory consumption after new, then delete

I created an example application as shown below. I have a requirement to create 1024 * 1024 structures. Before calling the operator, newmy application consumes a certain amount of memory (say, 0.3 MB). After calling a new operator, the memory increases (say, 175 mb). After calling the operator, the deletememory decreases (say, 15 mb). So finally, there is a difference in memory. I looked at all the memory data from the task manager. I am confused, should this be considered a memory leak, or will this memory be released slowly? If not, how can I free this remaining memory?

struct testSt
{
    bool        check;
    std::string testString; 

};

int main()
{
    testSt *testObj = new testSt[1024 * 1024];
    delete[] testObj;

    return 0;
}
+4
source share
3 answers

. , , , ++. , , , , , ++, .

, valgrind, .

, . ++. ,

std::vector<testSt> testObj(1024*1024);

.

+7

. , , , , , , () , . . ; , , . , , , , .

+1

, . :

struct testSt
{
    bool        check;
    std::string testString;

    ~testSt()
    {
        std::cout << "Destroyed!" << std::endl;
    }
};

Do you work with a debugger? Additional memory can be stored in the IDE.

0
source

Source: https://habr.com/ru/post/1695759/


All Articles