Does Ubuntu automatically release memory allocated by a C program as the program terminates?

ashubuntu

I have written a C program containing code allocating memory using the malloc() function. If I don't free up the memory using the free() function, will Ubuntu release it automatically?

kos

Yes.

The kernel will release all the resources allocated by a program upon the program's termination.

This is done after the do_exit() function defined in kernel/exit.c has terminated its execution; the do_exit() function execution itself might be triggered by a number of events, most commonly by an explicit exit() syscall called by the program during its regular computation or by an implicit exit() syscall called by the program upon its termination (as the C compiler places an exit() syscall after main()'s return). Other reasons include the reception of an unhandable / not ignorable signal or exception.

The do_exit() function itself performs a number of tasks. After it has terminated its execution, the program's allocated resources are released by the kernel and returned to the system for further uses.

Source

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

C Program Issue "pointer being freed was not allocated"

분류에서Dev

Program terminates without printing anything

분류에서Dev

Why does ubuntu not seem to release memory?

분류에서Dev

LLVM IR with Itanium terminates the program unexpectedly

분류에서Dev

error with string in dynamic memory c++ program

분류에서Dev

What happens when a program needs more memory than what was initially allocated to it?

분류에서Dev

Ubuntu의 C : \ Program Files 폴더

분류에서Dev

Why this Ansi C program does not give result?

분류에서Dev

Why does this C program crash? No bugs are reported

분류에서Dev

uninitialized data segment of program memory

분류에서Dev

Does nullptr release the memory of a pointer?

분류에서Dev

Why does this program loop?

분류에서Dev

C GtkTreeModel/Store memory release

분류에서Dev

How to automatically restart a program after it's closed

분류에서Dev

'Detach' from program terminal Ubuntu

분류에서Dev

Trying to compile a C program

분류에서Dev

Trying to compile a C program

분류에서Dev

Prime number program in C

분류에서Dev

C program display order

분류에서Dev

Java Eclipse console terminates program before comparing values of user input and string value

분류에서Dev

How does a shell execute a program?

분류에서Dev

Stop a program before it uses too much memory

분류에서Dev

When does garbage collection happen, between program start and program end?

분류에서Dev

Executing C++ program on Geany

분류에서Dev

Three dimensional array in c program

분류에서Dev

Python Script to run a C Program

분류에서Dev

C fork program behaviour explanation

분류에서Dev

c++ program error (fix)

분류에서Dev

Ubuntu freezes when running program on many threads