Reputation: 61
I have a c program that makes memory request. After that run my program i use the free -g -t command to see the memory used. The program call to the malloc function, but it does not call the free function. For example: pointer=malloc(900000000*sizeof(double)) I thought that that called would occupy ram memory but when i used the free command the free memory does not change . About 6 mega. I run the program a lot of times. The program don t free the memory but the free memory does not change. i thouhgt that the operation free memory was in charge of the programmer in c. My program is some more complicated than that, but the main operation is like that.
I don t underestand why the free (and occupped) memory does not change.
Upvotes: 0
Views: 255
Reputation: 330
As Jonathan Leffler says in his comment, malloc() does not actually allocate the memory you ask for in physical memory, that happens first when you use the memory. If you write to the memory you got from malloc() then you will see that memory usage as seen by "free" will increase.
From malloc man page under Notes:
By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available.
"free" reports the physical memory usage, as mentioned in free man page
Upvotes: 2