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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:22:03+00:00 2026-05-26T22:22:03+00:00

When loading images into the app with [UIImage imageNamed: fileName] , the system caches

  • 0

When loading images into the app with [UIImage imageNamed: fileName], the system caches the images and therefore provides a performance boost when the same image is used again.

Is there something similar for images created with Core Graphics? I mean images created from contexts with the UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); method.

The current approach I have is to draw the image and save the UIImage to disk, so that next time I need to use the same drawing method I can simply load the cached image from disk. I’m looking for a better way to store Core Graphics generated images as the current approach seems cumbersome.

Maybe even store the CGContextRef with all the drawing in some caching data-structure, I’m not quite sure if that’s possible?

My aim is to use only Core Graphics so my app bundle is smaller and I get resolution independence, but I’d like to improve the performance as complicated drawing routines can take a lot of time to process.

UPDATE: After doing some performance testing here are my results. Each time is an average over 100 runs, either drawing 19 or 25 different views at a time. Views included, rectangles, circles, but also text as UILabels. Fills, strokes, gradients and shadows were used.

Caching was implemented as discussed in the answer, with a NSDictionary storing the UIImage objects. Every run had an individual cache, which was used within the run, but not for all the views (out of 25, there were 2 sets of 8, 2 sets of 6 out of 19, which were identical and could be cached).

Here are the times:
iOS Simulator

19 views

No caching – average run 11.667ms

Caching – average run 10.321ms

25 views

No caching – average run 14.304ms

Caching – average run 13.509ms

Device

19 views

No caching – average 82.785ms
Caching – average 77.831ms

25 views

No caching – average 107.977ms
Caching – average 100.094ms

There is a remarkable difference (almost 8%) between the times and when accounting for the longer first time (to save to cache) it would still be beneficial to use the cache.

  • 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-26T22:22:04+00:00Added an answer on May 26, 2026 at 10:22 pm

    I’ve no performance data to back this up but I think the UIImage caching when using imageNamed is to save reading the file from “disk” and converting the png or whatever to UIImage data.

    Therefore your approach of writing to disk would seem to be an unnecessary step – once you have your UIImage object, this is as optimised as you are going to get.

    You could consider something like an image “factory” singleton which lazily creates images as they are requested – so the first time, it would do the requisite core graphics operations to create the UIImage, and thereafter return the completed object. Each different image would just be stored as an ivar in your factory.

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

Sidebar

Related Questions

I am loading images into a UIImage with the values of a slider (these
I'm loading images from my phone gallery and loading it into my app gallery,
I'm doing some lazy loading of images into an array when the app has
First time loading remote images into an iPhone app, and would like some help
Loading images into Flex (size < 100kb) causes IE7 memory increase by a megabyte
I have a fair few images that I'm loading into a ListBox in my
I keep running across this loading image http://georgia.ubuntuforums.com/images/misc/lightbox_progress.gif which seems to have entered into
I'm working on a small project that involves me loading an image into a
I'm loading a 8bppIndexed greyscale image into memory and reading the pixel values. The
I'm loading layers of images to make a single image. I'm currently stacking them

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.