Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

c++ - Memory usage isn't decreasing when using free?

Somehow this call to free() is not working. I ran this application on Windows and followed the memory using in Task Manager, but saw no reduction in memory usage after the call to 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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Typical C implementations do not return free:d memory to the operating system. It is available for use by the same program, but not to others.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...