2

If i allocate some memory inside my application and don't free them using delete or delete[] operators, Would they be freed upon exiting the application or sudden termination of the application?

Hossein
  • 24,202
  • 35
  • 119
  • 224
  • 7
    This is really up to the OS. In general yes, but nothing rules out an OS that doesn't do that. – juanchopanza Jun 27 '13 at 06:12
  • Most of the modern OS do that. But some small embedded systems might not. – WiSaGaN Jun 27 '13 at 06:40
  • and an answer IS still missing ? so the catch is only in embded systems right ? and is that actually garbage collecting? – Hossein Jun 27 '13 at 07:52
  • 2
    I was going to suggest that this is a duplicate of [What happens to memory that is not freed after the end of the program](http://stackoverflow.com/questions/864204/what-happens-to-memory-that-is-not-freed-after-end-of-program). But given you last comment, I wonder if you'd like to change your question to address (certain) embedded systems specifically. Otherwise, the other question covers pretty much all of it. – jogojapan Jun 27 '13 at 07:56
  • 2
    @Hossein What you are asking is not garbage collection. GC is a mechanism that frees any unused allocated objects during program execution. GC is not done by the OS, is done by the virtualized environment in which the application runs. You are asking if the OS is freeing memory after the program exists and the answer is yes for most usual OS. – banuj Jun 27 '13 at 07:57
  • 1
    possible duplicate of [Can a memory block allocated by using operator new/malloc persist beyond end of program execution?](http://stackoverflow.com/questions/11383401/can-a-memory-block-allocated-by-using-operator-new-malloc-persist-beyond-end-of) – interjay Jun 27 '13 at 07:58
  • possible duplicate of [What REALLY happens when you don't free after malloc?](http://stackoverflow.com/questions/654754/what-really-happens-when-you-dont-free-after-malloc) – stefan Jun 27 '13 at 08:59
  • Generally speaking, don't do that. Clean up after yourself. Don't rely on the OS to do it for you. (Not until you understand when that it is appropriate.) – Andre Kostur Jun 27 '13 at 13:46

1 Answers1

1

If the question is about C++, I would say it is not described in the standard. As juanchopanza said right, that's an OS issue to deallocate memory or to not. I think, general purpose OSes are deallocating usually, but embedded or real-time OSes may not.

Alexander Mihailov
  • 1,154
  • 7
  • 15