Alex Rivera | Logout

When you exit a C application, is the malloc-ed memory automatically freed?

Asked 2010-02-06T15:37:21.790
116

Let's say I have the following C code:

int main () {
  int *p = malloc(10 * sizeof *p);
  *p = 42;
  return 0;  //Exiting without freeing the allocated memory
}

When I compile and execute that C program, ie after allocating some space in memory, will that memory I allocated be still allocated (ie basically taking up space) after I exit the application and the process terminates?

Edit
Report

1 Answer

0

That really depends on the operating system, but for all operating systems you'll ever encounter, the memory allocation will disappear when the process exits.

answered 2010-02-06T15:40:17.470

Your Answer