Heap and OS memory at the output of a process written in C ++

I now doubt the role of the operating system in relation to the life cycle of the process. I am using Linux.

Suppose I have an application that creates a collection of objects on a heap using new. During the life of the application, I do not need to delete any of these objects, except when exiting the application or an exception, before exiting to perform the cleanup.

Suppose I do not call delete at the end of the application for all of these objects, does the OS usually restore / free the entire heap allocated to make it available again when the process terminates? If a process exits due to an exception or call to return or exit, does this always happen?

If so, it means that if I do not call delete, it will not affect the operation of the OS or other applications running on the machine. Correctly?

I usually use boost shared pointersor use delete, but I would just like to clarify this doubt in the context of OS / Linux

Regards AFG

+3
source share
5 answers

It is right. Any memory leak after the life of the process in the protected mode operating system is a really nasty bug in the kernel (sometimes a malfunction occurs).

, - , , . delete , .

+5

. , ..

+3

, . , , , , .

FYI : . RAII . ++, RAII, .

+1

, . - , .

Herb Satter , .

, .

( )

0

You need to be more careful with other resources such as file descriptors, database connections, etc. However, all memory is definitely fixed.

0
source

Source: https://habr.com/ru/post/1780408/


All Articles