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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:42:16+00:00 2026-05-28T07:42:16+00:00

I am working on an iOS project that loads UIImages from URLs in a

  • 0

I am working on an iOS project that loads UIImages from URLs in a background thread and displays them in a horizontally paged scroll view. This behavior should mimic that of the native photo library application for iPhone. I have everything setup in a way that I believe should work, but upon drawing the UIImages in the main UI graphics context, I occasionally see this message print out in the console:

ImageIO: <ERROR>  CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedImageBlockData: bad readSession [0x685e590]

Despite this error, it appears that the app functions perfectly fine, and that the images draw as expected. Should I simply ignore this “ERROR,” or should I change my method for loading images in the background thread? Currently, I load the image in a background thread using the UIImage initWithData: method:

- (void)backgroundLoadThread:(NSURL *)url {
    @autoreleasepool {
        NSData * imageData = [NSData dataWithContentsOfURL:url];
        UIImage * theImage = [[UIImage alloc] initWithData:imageData];
        if ([[NSThread currentThread] isCancelled]) {
#if !__has_feature(objc_arc)
            [theImage release];
#endif
            return;
        }
        [self performSelectorOnMainThread:@selector(loadComplete:)
                               withObject:theImage waitUntilDone:NO];
    }
}

My loadComplete: method simply retains the image passed as an instance variable, which is later drawn in the view’s drawRect: method. In drawRect:, I am using the UIImage drawInRect: method, which appears to be the perpetrator for the error message in the console. However, drawing the image’s underlying CGImageRef using CGContextDrawImage still causes the same error. The full source code can be found in this project’s Github repository, in the file ANAsyncImageView.m.

EDIT: I have now changed the background thread to load a CGImage from the file, and then callback to the main thread, passing the CGImageRef using toll-free bridging. Unfortunately, this still creates the same issue, proving to me that UIImage’s imageWithCGImage: must in some way keep a reference to the original CGImage. Check out the code in the file linked above (to the Github repository) for the full code:

NSData * imageData = [NSData dataWithContentsOfURL:url];
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)imageData);
CGImageRef loaded = CGImageCreateWithPNGDataProvider(provider, NULL, false, kCGRenderingIntentDefault);
CGDataProviderRelease(provider);

id imageObj = (id)loaded;        
[self performSelectorOnMainThread:@selector(loadComplete:) withObject:imageObj waitUntilDone:NO];
CGImageRelease(loaded);
  • 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-28T07:42:17+00:00Added an answer on May 28, 2026 at 7:42 am

    UIKit is not a thread-safe class. Therefore, you should not call UIImage from the background.

    Rather than create UIImages, render your images files into CGImageRefs. You can pass one of these back to the main thread and generate a UIImage from that (you will have still benefited by moving the heavy-lifting of image decompression to the background).

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

Sidebar

Related Questions

I'm working on an iOS project that has to work from iOS4. I have
I'm working on a project that generates a iOS static library, and some sample
I'm new to ios i'm working in a small project in that i need
I'm new to iOS programming and I am working on a easy project that
I'm working on a project that involves a native iOS client as well as
I'm working on a project that consist in an IOS App and a webservice
Working on an iOS project that targets 4.0 and 5.0, using ARC. Running into
I am working on an iOS project that needs to encode and decode Speex
I am doing iOS project in Xcode . It was working properly but now
I am working on a iOS 5 iPhone project where users can choose an

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.