In an application of mine I basically allocate memory in C++ and enqueue it for deallocation in C#. This deallocation runs in the background and is non-deterministic, so in very rare cases it can theoretically happen that the application is exited before all the unmanaged memory is deallocated.
If that is the case, the behaviour is (roughly and very stripped down) the same as if my program was
int main()
{
Foo* = new Foo();
return 0;
}
my questions now are
- Is all the memory a program allocates, but not deallocates automatically reclaimed when the program exits or is it a memory leak that stays until I reboot?
- If it is automatically reclaimed, what mechanism is responsible for that?
EDIT: This is about Windows only, as some mentioned that this is OS-dependent.
EDIT 2: I am not talking about simply ignoring all memory leaks in my application, but about whether I need to make sure that all memory is properly deallocated right before the application exits.
EDIT 3: This is not about open file handles, destructors and side effects or anything, this is about memory that will be non-deterministically deallocated and very rare cases where the memory is not freed before termination.