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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:58+00:00 2026-05-26T15:14:58+00:00

Is there any way to find out how much memory is available in iOS?

  • 0

Is there any way to find out how much memory is available in iOS? I know that the system will pass low memory warnings when available memory gets low. However, my App has some points where a single thread will perform a complex task and sometimes that task uses up enough memory that it is just terminated by the OS (my app can download pictures from the internet, and I scale them down to a small size … if the user downloads a very large image, my app runs out of memory and just goes ‘poof’).

Having the App spontaneously terminate is obviously a poor user experience.

Is there any way that I can find out when I am about to run out of memory and stop the task instead?

I suppose I could put the task on a separate thread, and maybe the system would send the main thread a low memory warning, but that seems pretty complicated and not even guaranteed to work.

Thanks!
Ron

  • 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-26T15:14:59+00:00Added an answer on May 26, 2026 at 3:14 pm

    While testing and debugging your app with XCode you can use this logMemUsage() function to NSLog the used/free space and watch how things are going while you test your app. This function logs any change in usage > 100kb. It outputs to the debug log like this (on the simulator the free space is huge):

    2011-11-02 21:55:58.928 hello[971:207] Memory used 21884.9 (+21885), free 1838366.8 kb
    2011-11-02 21:55:59.936 hello[971:207] Memory used 28512.3 (+6627), free 1830809.6 kb
    2011-11-02 21:56:01.936 hello[971:207] Memory used 28803.1 ( +291), free 1830129.6 kb
    2011-11-02 21:56:02.936 hello[971:207] Memory used 29712.4 ( +909), free 1830142.0 kb
    

    You decide where to call logMemUsage in your app. I happen to have a function that is called by a timer every second and so I put it in there. I suggest using #ifdef around these so this code is only included in Debug builds.

    #import "mach/mach.h" 
    
    vm_size_t usedMemory(void) {
        struct task_basic_info info;
        mach_msg_type_number_t size = sizeof(info);
        kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
        return (kerr == KERN_SUCCESS) ? info.resident_size : 0; // size in bytes
    }
    
    vm_size_t freeMemory(void) {
        mach_port_t host_port = mach_host_self();
        mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
        vm_size_t pagesize;
        vm_statistics_data_t vm_stat;
    
        host_page_size(host_port, &pagesize);
        (void) host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
        return vm_stat.free_count * pagesize;
    }
    
    void logMemUsage(void) {
        // compute memory usage and log if different by >= 100k
        static long prevMemUsage = 0;
        long curMemUsage = usedMemory();
        long memUsageDiff = curMemUsage - prevMemUsage;
    
        if (memUsageDiff > 100000 || memUsageDiff < -100000) {
            prevMemUsage = curMemUsage;
            NSLog(@"Memory used %7.1f (%+5.0f), free %7.1f kb", curMemUsage/1000.0f, memUsageDiff/1000.0f, freeMemory()/1000.0f);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to find out diagonals of quadrilateral if I only know
is there any way to find out new version of application is available on
Is there any way to find out or store which app is accessing an
What have I marked as --assume-unchanged ? Is there any way to find out
I have a table with many rows, is there any way to find out
Is there any way possible to find out the total number of sent emails
Is there any way I can find out in my app if the user
Is there any way to (programatically) find out what your app's name is? I'm
Is there any easy way to find out what T-SQL is being generated by
Is there any way how we can find out the number of prints taken

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.