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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:58+00:00 2026-06-10T19:52:58+00:00

So, this is what I’m trying to do : Free up system memory (inactive

  • 0

So, this is what I’m trying to do :

  • Free up system memory (inactive memory), in the same fashion the purge command does, though programmatically.

I’ve tried the code here (which its author claims it works), but all it does is to cause Mac OS X to freeze :

void
free_up_memory()
{
    int c;
    char *p, *q;

    for(c = 0; c < 2048; c++)
    {
        if(!(p = malloc(1024 * 1024)))
        {

            return;
        }
        for(q = p; q < p + (1024 * 1024); q += 4096)
        {
            *q = 1;
        }

    }
}

Any ideas?

  • 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-10T19:53:00+00:00Added an answer on June 10, 2026 at 7:53 pm

    The reality is that code is not doing — and will never do — what it claims. It is garbage.

    All it is going to do is undermine the system’s buffer caching subsystem and likely drive the machine into paging rapidly, causing symptoms that look entirely like a lockup. Especially on a system with a slow (5,400rpm laptop drive, for example) hard drive.

    At least, on systems with relatively small amounts of RAM. On systems with larger amounts of RAM and relatively light load of apps running, that program is going to evict 2GB of buffer caches, causing various I/O operations to be slower as various things need to be re-read from disk, and not really help anything.

    Nor should any such thing be necessary; if an app needs memory, the system will evict pages from the buffer caches and/or page out memory to disk as needed (on OS X — on iOS there is no pager capable of writing dirty pages largely to preserve responsiveness).

    Calling out to purge will evict the various disk buffer caches and simulate conditions at a cold boot, but — again — that just undermines the system’s caching mechanisms without actually increasing performance for user level apps. As the man page documents, it can be quite useful for testing app performance in a cold cache state, but even that is a bit dubious in that purge won’t evict everything that can be evicted; won’t cleanly simulate a cold state.

    To Steve Jessep’s quite valid point, there may be situations where a call to purge (or the like) might increase performance in that case. This typically — almost universally — falls apart in the general case in that there is no way for user process A to know what user processes B,C,D,….,Z might do at any point in the near or distant future. Example; A might go and purge stuff only to have RSS Feed Scraper R rip down a few MB of XML to be parsed and persisted, immediately invalidating the purge. Worse, R’s last refresh may have had bits still lurking in the cache such that R’s refresh pounds on I/O making it both slower and more costly (including costing battery life).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This is what i tried . In my view.py file , import logging logger
This has been posted, but I've tried lot of solutions found on SO and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes
This question is kind of a follow up to this question I asked a
This should be a simple one: I have an observableArray object called To in
This sequence satisfies a(n+2) = 2 a(n+1) + 2 a(n). and also a(n)=[(1+sqrt(3))^(n+2)-(1-sqrt(3))^(n+2)]/(4sqrt(3)). I

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.