小编pat*_*iot的帖子

malloc()可能发生内存泄漏

我有这个代码:

#include <malloc.h>

int main()
{
    int x = 1000;

    //~600kb memory at this point
    auto m = (void**)malloc(x * sizeof(void*));
    for (int i = 0; i < x; i++)
        m[i] = malloc(x * sizeof(void*));

    for (int i = 0; i < x; i++)
        free(m[i]);

    free(m);

    //~1700kb memory at this point
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当程序启动时,内存消耗约为~600kb,当它结束时约为1700kb.是内存泄漏还是什么?

c++ memory-leaks

2
推荐指数
1
解决办法
164
查看次数

标签 统计

c++ ×1

memory-leaks ×1