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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:29:24+00:00 2026-06-10T15:29:24+00:00

I have come across an issue when loading different NSImages repeatedly in an application

  • 0

I have come across an issue when loading different NSImages repeatedly in an application written using Automatic Reference Counting. It seems as though ARC is not releasing the image objects correctly, and instead the memory usage increases as the list is iterated until the iteration is complete, at which point the memory is freed.

I am seeing up to 2GB of memory being used through the process in some cases. There’s a good discussion on SO on a very similar issue which ends up putting the process in an NSAutoReleasePool and releasing the image and draining the pool. This works for me as well if I don’t use ARC, but it is not possible to make calls to these objects / methods in ARC.

Is there any way to make this work in ARC as well? It seems as though ARC should be figuring this out all by itself – which makes me think that the fact that these objects are not getting released must be a bug is OS X. (I’m running Lion with XCode 4.2.1).

The kind of code which is causing the issue looks like this:

+(BOOL)checkImage:(NSURL *)imageURL
{
    NSImage *img = [[NSImage alloc] initWithContentsOfURL:imageURL];
    if (!img)
         return NO;

    // Do some processing
    return YES;
}

This method is called repeatedly in a loop (for example, 300 times). Profiling the app, the memory usage continues to increase with 7.5MB alloced for each image. If ARC is not used, the following can be done (as suggested in this topic):

+(BOOL)checkImage:(NSURL *)imageURL
{
    NSAutoReleasePool *apool = [[NSAutoReleasePool alloc] init];
    NSImage *img = [[NSImage alloc] initWithContentsOfURL:imageURL];
    if (!img)
         return NO;

    // Do some processing

    [img release];
    [apool drain];

    return YES;
}

Does anyone know how to force ARC to do the memory cleaning? For the time being, I have put the function in a file which is compiled with -fno-objc-arc passed in as a compiler flag. This works OK, but it would be nice to have ARC do it for me.

  • 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-10T15:29:26+00:00Added an answer on June 10, 2026 at 3:29 pm

    use @autoreleasepool, like so:

    +(BOOL)checkImage:(NSURL *)imageURL
    {
        @autoreleasepool { // << push a new pool on the autotrelease pool stack
          NSImage *img = [[NSImage alloc] initWithContentsOfURL:imageURL];
          if (!img) {
             return NO;
          }
          // Do some processing
        } // << pushed pool popped at scope exit
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across this issue in my application, and have reproduced it using Apple's
I have come across an issue with my application, I have an option class
I've been working on a web application using Bootstrap, and have come across odd
I am developing a webapp for ipad and have come across an issue using
I have come across a very strange issue in python. (Using python 2.4.x) In
I'm using Entity Framework and have come across an issue with the lack of
I have recently started learning c# and have come across an issue. I'm not
I have never come across this issue but most recently I noticed that a
hey there i wonder if any of you have come across a similar issue?
I'm just learning nHibernate and have come across what probably is a simple issue

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.