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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:32:57+00:00 2026-06-10T11:32:57+00:00

I have been running overnight memory tests on an embedded Linux system. Using vmstat

  • 0

I have been running overnight memory tests on an embedded Linux system. Using vmstat I have observed that the free memory steadily decreases over time. According to some smaps analysis in procfs, the heap of one process grows at roughly the same rate. I suspected a memory leak and found a few spots in the code where new and delete are regularly used. However, I did not see a new calls without matching delete calls.

I ran the memory test again and this morning cleared the memory caches with the following call

echo 3 > /proc/sys/vm/drop_caches

The free memory listed in vmstat went down to a value close to when the test was started.

Does the kernel regularly reclaim unused heap pages? If so, are there other times besides the one above that this is done? Probably when free memory gets below a certain threshold?

  • 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-10T11:32:58+00:00Added an answer on June 10, 2026 at 11:32 am

    As others said, it is the process’s duty to return memory to the kernel.

    Usually there are 2 ways to allocate memory: if you malloc()/new a memory block above a certain size, the memory gets allocated from the OS via mmap() and eturned as soon as it is free. Smaller blocks are allocated by increasing the process’s data area by shifting the sbrk border upwards. This memory is only freed if a block over a certain size is free at the end of that segment.

    E.g.: (pseudo code, I don’t know C++ very well)

    a = new char[1000];
    b = new char[1000];
    

    Memory map:

    ---------------+---+---+
    end of program | a | b |
    ---------------+---+---+
    

    If you free a now, you have a hole in the middle. It is not freed because it cannot be freed.
    If you free b, the process’s memory may or may not be reduced; the unused remainder is returned to the system.

    A test with a program as simple as

    #include <stdlib.h>
    
    int main()
    {
        char * a = malloc(100000);
        char * b = malloc(100000);
        char * c = malloc(100000);
        free(c);
        free(b);
        free(a);
    }
    

    leads to a strace output like

    brk(0)                                  = 0x804b000
    brk(0x8084000)                          = 0x8084000
    brk(0x80b5000)                          = 0x80b5000
    brk(0x809c000)                          = 0x809c000
    brk(0x8084000)                          = 0x8084000
    brk(0x806c000)                          = 0x806c000
    

    is shows that the brk value is first increased (for malloc()) and then decreased again (for free()).

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

Sidebar

Related Questions

I have been using this code, but have been running into some memory issues:
We have a Linux server that has been running our MySQL 5.1 server. For
I have been running some small tests in PHP on loops. I do not
I have been running up a stored procedure that runs several separate update and
I am currently developing on an advertising system, which have been running just fine
I have been running tests towards a Core Data model (SQLite3). I now need
I have suddenly been getting the memory exception errors for two programs running on
We have a legacy vb6 program using Active Reports 2. We have been running
Good morning I have been running a few tests over the past couple of
We recently started using Eclipse to develop our java application and have been running

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.