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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:56:52+00:00 2026-05-31T16:56:52+00:00

I have an ARC based app which loads about 2,000 fairly large (1-4MB) Base64

  • 0

I have an ARC based app which loads about 2,000 fairly large (1-4MB) Base64 encoded images from a webservice. It converts the Base64 decoded strings to .png image files and saves them to the disk. This is all done in a loop where i shouldn’t have any lingering references.

I profiled my app and found out that UIImagePNGRepresentation was hogging around 50% of available memory.

The way i see it, UIImagePNGRepresentation is caching the images it creates. One way to fix this would be to flush that cache. Any ideas how one might do that?

Another solution would be to use something other than UIImagePNGRepresentation?

I already tried out this with no luck: Memory issue in using UIImagePNGRepresentation. Not to mention that i can’t really use the solution provided there ’cause it would make my app too slow.

This is the method i call from my loop. UIImage is the image converted from Base64:

+ (void)saveImage:(UIImage*)image:(NSString*)imageName:(NSString*)directory {
  NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
  NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
  NSString *pathToFolder = [documentsDirectory stringByAppendingPathComponent:directory];

  if (![fileManager fileExistsAtPath:pathToFolder]) {
    if(![fileManager createDirectoryAtPath:pathToFolder withIntermediateDirectories:YES attributes:nil error:NULL]) {
       // Error handling removed for brevity
    }
  }

  NSString *fullPath = [pathToFolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
  [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)

  // clear memory (this did nothing to improve memory management)
  imageData = nil;
  fileManager = nil; 
}

EDIT:
Image dimensions vary roughly from 1000*800 to 3000*2000.

  • 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-31T16:56:53+00:00Added an answer on May 31, 2026 at 4:56 pm

    You could wrap the method body by a autorelease pool

    + (void)saveImage:(UIImage*)image:(NSString*)imageName:(NSString*)directory {
    
        @autoreleasepool
        {
            NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
            NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
            NSString *pathToFolder = [documentsDirectory stringByAppendingPathComponent:directory];
    
            if (![fileManager fileExistsAtPath:pathToFolder]) {
              if(![fileManager createDirectoryAtPath:pathToFolder withIntermediateDirectories:YES attributes:nil error:NULL]) {
                 // Error handling removed for brevity
              }
            }
    
            NSString *fullPath = [pathToFolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
            [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
        }
    }
    

    But actually it could be helpful, if you provide us with some more numbers:
    What dimensions do the images have. This is important, as image data is stored in memory in raw pixels. iE a image 2000px width * 2000px height * 4 Bytes (RGBA) ~ 15MB. Now imagine, that the converting algorithm will have to store informations for every pixel or at least some area. Huge numbers are to be expected.

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

Sidebar

Related Questions

I have an iOS-App which uses ARC. I don't use InterfaceBuilder, all UI is
Simple scenario: table view controller, with 5.000 rows. I have 5000 images name from
I have an interesting question about interface builder and ARC. I am building a
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
In a doc-based ARC-enabled application I have a WebView that is opening an HTML
I have a base class line which has a child class arc (note that
I have been reading up alot about Arc and it seems to provide some
I have an app with both ARC code and non-ARC code. The compiler will
I have a iOS project in which I am using ARC in my own
I have started using (ARC) with iOS 5, but I have a problem which

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.