Jul 30, 2001
Memory Deallocation Myths
A common myth among programmers says that you can avoid calling delete in your application because the operating system will release the allocated memory when the application terminates anyways. Indeed, modern operating systems release leaked memory after an application terminates. However, there's a substantial difference between releasing raw memory and properly destroying objects. The operating system will perform the former operation but it will not call object's destructors, flush unclosed streams, release locks, and so on. Therefore, never rely on the operating system's cleanup operation. Instead, delete all allocated objects before the application terminates.