P
pushpakulkar
Hi all,
Suppose you have simple piece of code something like this. It is only
for testing purpose, please pardon
syntax errors.
#include <malloc.h>
#include <stdio.h>
int main()
{
int k=1;
int *p;
if(k)
{
p=(int *)malloc(1024*1024);
if(p)
{
printf("Malloc successful\n");
//Point A - Do something .....................
// .........................................
free(p);
//Point B - Do something
else .........................
//......................................................
}
return 1;
}
My question is that at Point B, size of process will be say 1872K(on
my system). After free(p) at Point B, size of the process will be say
around 872K. Though the freed up memory is showing up on the size of
process, I have heard that some processes don't really return the
memory to the OS, rather it is marked as free() and will be released
to the operating system only after the program exits. Also this memory
can be released when there is a requirement. If the process doesn't
return the memory to the operating system, does it not reflect on the
size of the process. Can someone please give some feedback on the
same.
Regards,
Push
Suppose you have simple piece of code something like this. It is only
for testing purpose, please pardon
syntax errors.
#include <malloc.h>
#include <stdio.h>
int main()
{
int k=1;
int *p;
if(k)
{
p=(int *)malloc(1024*1024);
if(p)
{
printf("Malloc successful\n");
//Point A - Do something .....................
// .........................................
free(p);
//Point B - Do something
else .........................
//......................................................
}
return 1;
}
My question is that at Point B, size of process will be say 1872K(on
my system). After free(p) at Point B, size of the process will be say
around 872K. Though the freed up memory is showing up on the size of
process, I have heard that some processes don't really return the
memory to the OS, rather it is marked as free() and will be released
to the operating system only after the program exits. Also this memory
can be released when there is a requirement. If the process doesn't
return the memory to the operating system, does it not reflect on the
size of the process. Can someone please give some feedback on the
same.
Regards,
Push