Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8188169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:48:56+00:00 2026-06-07T02:48:56+00:00

Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed?

  • 0

Possible Duplicate:
When you exit a C application, is the malloc-ed memory automatically freed?

This question came to my mind when i was reading about how compulsory it is to use delete/free respectively when it comes to dynamic memory allocation in C/C++. I thought if the memory allocation persisted beyond the termination of my program execution, then yes it is compulsory; otherwise, why do i have to worry about freeing up the allocated space? Isn’t the OS going to free it up automatically with process termination? How right am i?
My question is that can

int *ip = new int(8);

persist beyond the termination of my program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:48:57+00:00Added an answer on June 7, 2026 at 2:48 am

    Short answer: No.

    Long answer: No. C++ will never persist memory unless you do the work to make it do so. The reason to free memory is this:

    If you don’t free memory, but keep allocating it, you will run out at some point. Once you run out, almost anything can happen. On Linux, maybe the OOM killer is activated and your process is killed. Maybe the OS pages you completely to disk. Maybe you give a Windows box a blue screen if you use enough memory. It can almost be thought of as undefined behavior. Also, if you leak memory, it’s just siting there, unused, unreleased, and no one can use it until your process terminates.

    There’s another reason too. When you release memory to the allocator, the allocator might keep it around, but just mark it as usable. That means that next time you need memory, it’s already sitting there waiting for you. That means there are less calls into the kernel to ask for memory, increasing performance, as context switches are very inefficient.

    EDIT: The C and C++ standards don’t even give a guarantee that the memory will be cleaned up by the OS after termination. Many OSes and compilers may, but there is no guarantee. Despite this, all major desktop and mobile operation systems (with the exception of probably DOS and some very old embedded systems) do clean up a processes memory after it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed?
Possible Duplicate: When you exit a C application, is the malloc-ed memory automatically freed?
Possible Duplicate: Proper way to exit iPhone application? How can I Crash my app?
Possible Duplicate: Windows Phone 7 close application How to Exit from the app when
Possible Duplicate: Java string comparison? I was trying to do this: boolean exit =
Possible Duplicate: android - exit application code I am finding the way to exit
Possible Duplicate: Returning in a static initializer Is there a way to exit a
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Automatic exit from bash shell script on error How can I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.