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

  • Home
  • SEARCH
  • 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 6039455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:22:15+00:00 2026-05-23T06:22:15+00:00

Possible Duplicate: Is freeing allocated memory needed when exiting a program in C I

  • 0

Possible Duplicate:
Is freeing allocated memory needed when exiting a program in C

I was reading the page “Freeing Memory Allocated with malloc“ and ran across this sentence:

There is no point in freeing blocks at the end of a program, because all of the program’s space is given back to the system when the process terminates.

I realize what the author is trying to say, but shouldn’t the sentence be:

There is no point in freeing blocks at the end of a program, because all of the program’s space is given back to the system when the process terminates, although you should still make sure you program frees all malloc’ed memory before exiting.

Or is it common practice to not de-allocate memory before the termination of the process?

  • 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-05-23T06:22:16+00:00Added an answer on May 23, 2026 at 6:22 am

    I’ve taken a lot of heat for this, but my position is that putting effort into freeing memory just before program exit should be Considered Harmful. For one thing it’s extra code to maintain and debug – but probably not too much, so that’s only a small issue. The much larger issue is practical effects.

    Suppose you have a long-lived program that’s allocated complex/deep data structures – as a good example, think of a web browser. It’s likely that much of this data has not been used in a while, and further that it’s been swapped to disk. If you just exit, the swapped-out data on disk is simply marked unused and never touched again. But if you walk through all your program’s data structures to free them, you will touch every single swapped-out page, causing:

    • disk access to read the swapped-out data
    • eviction of other programs’ actually-important data from memory
    • and corresponding disk access to swap out said data belonging to other programs.

    All of this wastes:

    • the user’s time
    • wear on the HDD (or even worse, on SSD/flash)

    This behavior is easily observable if you overload your system with enough bloated desktop apps (Firefox, OpenOffice, GIMP, etc. or Windows equivalents) to get it swapping, then try to close one of them. You’ll spend several seconds (maybe even ~30 sec it the swapping is bad enough) waiting for it to exit. If the program had just called exit directly (after checking for unsaved documents and whatnot) it would have closed immediately.

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

Sidebar

Related Questions

Possible Duplicate: ( POD )freeing memory : is delete[] equal to delete ? Does
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: What REALLY happens when you don’t free after malloc? When ending a
Possible Duplicate: Difference between Convert.tostring() and .tostring() Hi Carrying on from this question What
Possible Duplicate: John Carmack’s Unusual Fast Inverse Square Root (Quake III) I came across
Possible Duplicate: or is not valid C++ : why does this code compile ?
Possible Duplicates: What's better at freeing memory with PHP: unset() or $var = null
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: C# Lambda ( => ) For instance Messenger.Default.Register<AboutToCloseMessage>(this, (msg) => { if
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

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.