P
pushpakulkar
Hi all,
If I have a piece of code something like this
int main()
{
char *s1;
s1= (char *) malloc(sizeof(char) * 200)
while(somecondition)
{
................... //do something
}
free(s1);
while(true)
{
;
} //Infinite loop
}
This is just a sample code, please ignore the syntax errors.
In the above piece of code during execution malloc results in
allocating space physically in the RAM. Now after the first while loop
execution is complete free(s1) is called. At this point of time is
memory returned back to the OS or not always. I guess memory is just
marked as freed for future use by the same process.
I have read that in some implementations of OS like some unix flavors
even after free() is executed memory is not released back to the
system. In the above piece of code is it the case that the memory is
never freed up at all in such implementations and remains tied up till
the process dies.
Assuming there is a need for memory by some other process and no other
free memory is available, is it the case malloc for the other process
would fail under such circumstances. Does the OS do some kind of
tracking and free up this memory. Is there any way to force freeing
up the memory to the system back.
Thanks and Regards,
Pushpa
If I have a piece of code something like this
int main()
{
char *s1;
s1= (char *) malloc(sizeof(char) * 200)
while(somecondition)
{
................... //do something
}
free(s1);
while(true)
{
;
} //Infinite loop
}
This is just a sample code, please ignore the syntax errors.
In the above piece of code during execution malloc results in
allocating space physically in the RAM. Now after the first while loop
execution is complete free(s1) is called. At this point of time is
memory returned back to the OS or not always. I guess memory is just
marked as freed for future use by the same process.
I have read that in some implementations of OS like some unix flavors
even after free() is executed memory is not released back to the
system. In the above piece of code is it the case that the memory is
never freed up at all in such implementations and remains tied up till
the process dies.
Assuming there is a need for memory by some other process and no other
free memory is available, is it the case malloc for the other process
would fail under such circumstances. Does the OS do some kind of
tracking and free up this memory. Is there any way to force freeing
up the memory to the system back.
Thanks and Regards,
Pushpa