使用免费时,内存使用量不会减少?

rpl*_*usg 2 c++ memory-leaks

不知何故,此调用free()无效.我在Windows上运行此应用程序并在任务管理器中使用内存,但在调用后没有看到内存使用量减少free().

int main(int argc, char *argv[])
{
    int i=0;
    int *ptr;

    ptr = (int*) malloc(sizeof(int) * 1000);

    for (i=0; i < 1000; i++)
    {
        ptr[i] = 0;
    }

    free(ptr); // After this call, the program memory usage doesn't decrease

    system("PAUSE");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Tho*_*thy 13

典型的C实现不会返回free:d内存到操作系统.它可以由同一程序使用,但不能供其他程序使用.

  • calvin:是的,你的程序没有任何问题.只是C运行时将内存保留在进程中. (3认同)