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 3212888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:53:06+00:00 2026-05-17T14:53:06+00:00

I have a long-living application with frequent memory allocation-deallocation. Will any malloc implementation return

  • 0

I have a long-living application with frequent memory allocation-deallocation. Will any malloc implementation return freed memory back to the system?

What is, in this respect, the behavior of:

  • ptmalloc 1, 2 (glibc default) or 3
  • dlmalloc
  • tcmalloc (google threaded malloc)
  • solaris 10-11 default malloc and mtmalloc
  • FreeBSD 8 default malloc (jemalloc)
  • Hoard malloc?

Update

If I have an application whose memory consumption can be very different in daytime and nighttime (e.g.), can I force any of malloc‘s to return freed memory to the system?

Without such return freed memory will be swapped out and in many times, but such memory contains only garbage.

  • 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-17T14:53:06+00:00Added an answer on May 17, 2026 at 2:53 pm

    The following analysis applies only to glibc (based on the ptmalloc2 algorithm).
    There are certain options that seem helpful to return the freed memory back to the system:

    1. mallopt() (defined in malloc.h) does provide an option to set the trim threshold value using one of the parameter option M_TRIM_THRESHOLD, this indicates the minimum amount of free memory (in bytes) allowed at the top of the data segment. If the amount falls below this threshold, glibc invokes brk() to give back memory to the kernel.

      The default value of M_TRIM_THRESHOLD in Linux is set to 128K, setting a smaller value might save space.

      The same behavior could be achieved by setting trim threshold value in the environment variable MALLOC_TRIM_THRESHOLD_, with no source changes absolutely.

      However, preliminary test programs run using M_TRIM_THRESHOLD has shown that even though the memory allocated by malloc does return to the system, the remaining portion of the actual chunk of memory (the arena) initially requested via brk() tends to be retained.

    2. It is possible to trim the memory arena and give any unused memory back to the system by calling malloc_trim(pad) (defined in malloc.h). This function resizes the data segment, leaving at least pad bytes at the end of it and failing if less than one page worth of bytes can be freed. Segment size is always a multiple of one page, which is 4,096 bytes on i386.

      The implementation of this modified behavior of free() using malloc_trim could be done using the malloc hook functionality. This would not require any source code changes to the core glibc library.

    3. Using madvise() system call inside the free implementation of glibc.

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

Sidebar

Related Questions

I have long recognized that any set of whitespace in an HTML file will
I have long since forgotten the password for the root user on one of
I have long been wondering why lazy evaluation is useful. I have yet to
I have long tables generated by datagrid control that go beyond the page width.
I have long been of the opinion that the time and resources it would
I wish to have long and short forms of command line options invoked using
I have a long running SQL statement that I want to run, and no
I have a long running process in VB6 that I want to finish before
I have several long running report type transactions that take 5-10 minutes. Would I
I have a long URL with tons of parameters that I want to open

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.