I know that if I don’t free allocated memory with delete/free I’d end up with memory leaks. My question is: if my program gets terminated, does the operating system free the memory for me even if I didn’t?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Whether the memory leaks or not depends on the Operating system. In case of most operating systems once the process in which your program runs exits the OS simply reclaims back the memory it allocated to the process.
There is another important aspect to it.
newresults in calling of the class constructor anddeleteresults in call to an destructor. So if you callednewand never calleddeletethen in addition to the so called memory leak which may/may not exist after the program exit there is an additional condition that if the destructor of the particular class invokes some code which has side effects then it results in Undefined Behavior.So the answer is it depends, You may possibly have:
C++11 Standard 3.8 Object lifetime:
Para 4: