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

The Archive Base Latest Questions

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

I’m building an app that has several different sections to it, all of which

  • 0

I’m building an app that has several different sections to it, all of which are pretty image-heavy. It ties in with my client’s website and they’re a “high-design” type outfit.

One piece of the app is images uploaded from the camera or the library, and a tableview that shows a grid of thumbnails. Pretty reliably, when I’m dealing with the camera version of UIImagePickerControl, I get hit for low memory. If I bounce around that part of the app for a while, I occasionally and non-repeatably crash with “status:10 (SIGBUS)” in the debugger.

On low memory warning, my root view controller for that aspect of the app goes to my data management singleton, cruises through the arrays of cached data, and kills the biggest piece, the image associated with each entry. Thusly:

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Low Memory Warning"
                                                    message:@"Cleaning out events data"
                                                   delegate:nil
                                          cancelButtonTitle:@"All right then."
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];

    NSInteger spaceSaved;

    DataManager *data = [DataManager sharedDataManager];
    for (Event *event in data.eventList) {
        spaceSaved += [(NSData *)UIImagePNGRepresentation(event.image) length];
        event.image = nil;
        spaceSaved -= [(NSData *)UIImagePNGRepresentation(event.image) length];
    }

    NSString *titleString = [NSString stringWithFormat:@"Saved %d on event images", spaceSaved];

    for (WondrMark *mark in data.wondrMarks) {
        spaceSaved += [(NSData *)UIImagePNGRepresentation(mark.image) length];
        mark.image = nil;
        spaceSaved -= [(NSData *)UIImagePNGRepresentation(mark.image) length];
    }

    NSString *messageString = [NSString stringWithFormat:@"And total %d on event and mark images", spaceSaved];

    NSLog(@"%@ - %@", titleString, messageString);

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

As you can see, I’m making a (poor) attempt to eyeball the memory space I’m freeing up. I know it’s not telling me about the actual memory footprint of the UIImages themselves, but it gives me SOME numbers at least, so I can see that SOMETHING’S happening. (Sorry for the hamfisted way I build that NSLog message too–I was going to fire another UIAlertView, but realized it’d be more useful to log it.)

Pretty reliably, after toodling around in the image portion of the app for a while, I’ll pull up the camera interface and get the low memory UIAlertView like three or four times in quick succession. Here’s the NSLog output from the last time I saw it:

2010-05-27 08:55:02.659 EverWondr[7974:207] Saved 109591 on event images - And total 1419756 on event and mark images
wait_fences: failed to receive reply: 10004003
2010-05-27 08:55:08.759 EverWondr[7974:207] Saved 4 on event images - And total 392695 on event and mark images
2010-05-27 08:55:14.865 EverWondr[7974:207] Saved 4 on event images - And total 873419 on event and mark images
2010-05-27 08:55:14.969 EverWondr[7974:207] Saved 4 on event images - And total 4 on event and mark images
2010-05-27 08:55:15.064 EverWondr[7974:207] Saved 4 on event images - And total 4 on event and mark images

And then pretty soon after that we get our SIGBUS exit. So that’s the situation. Now my specific questions:

THE time I see this happening is when the UIPickerView’s camera iris shuts. I click the button to take the picture, it does the “click” animation, and Instruments shows my memory footprint going from about 10mb to about 25mb, and sitting there until the image is delivered to my UIViewController, where usage drops back to 10 or 11mb again. If we make it through that without a memory warning, we’re golden, but most likely we don’t. Anything I can do to make that not be so expensive?

Second, I have NSZombies enabled. Am I understanding correctly that that’s actually preventing memory from being freed? Am I subjecting my app to an unfair test environment?

Third, is there some way to programmatically get my memory usage? Or at least the usage for a UIImage object? I’ve scoured the docs and don’t see anything about that.

  • 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-15T03:10:22+00:00Added an answer on May 15, 2026 at 3:10 am

    These functions give you an idea of your total memory usage and total free memory. I happen to have a 1 sec timer in my app, every second it logs used and free memory space (if either changed > 0.5mb), it helps me see better whats going on:

    #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
    }
    
    natural_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;
    }
    

    EDIT1 – function class_getInstanceSize gives you the size of an object instance, but I’ve never tried it and it probably doesn’t dereference the ivars and rollup their usage. But maybe it can help you.

    EDIT2 This function gives you the size of a UIImage:

    size_t sizeofUIImage(UIImage* image) {
        return CGImageGetBytesPerRow(image.CGImage) * CGImageGetHeight(image.CGImage);
    }
    

    EDIT4 Here is a bit of code from my 1 sec timer handler method, it helps see how your app is doing before you have memory problems. Of course, free memory varies depending on what background tasks are running (Safari, Mail, etc) which you don’t have much control over:

    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);
        }
    }
    

    Credits: memory free/used functions derived from here and here.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is

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.