mangesh wrote:
consider following code :
void fun()
{
int a ;
//..do something
}
when function exit , a is said to be deleted . My confusion is who
deletes a , compiler or os . And if by os which part of os .
Well, you've missed a candidate, and it's the one that does the
work. It's your program.
The compiler creates your program. The compiler is not necessarily
even loaded when your program runs. In fact, the compiler might not
be on the same machine. Hey, in theory, the compiler might have
been completely erased from all machines everywhere, not even a
backup existing, when your program runs. (Though I suppose that
does not happen all that often.)
The OS does not know about the variables in your program. Nor care.
It grabs your program out of storage and sticks it in the part of
memory that contains programs while they execute, then passes
control to your program. And that's just about it while your prog
is running. There may be some other services like disk access or
swapping and so on. But the OS does not know about variables.
For simple variables like ints, all your program does to delete the
variable is change the stack pointer so that the variable is no
longer in the part of the stack your program expects to be data.
For variables that are instances of a class with a destructor,
your program calls the dtor for that object before it changes
the stack pointer. All that goes on "behind the scenes" where
you don't have to pay attention to it. Thus such variables are
called "automatic variables." It is part of your program, in stuff
created by the compiler. But the work is done by your program.
Socks