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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:02:40+00:00 2026-06-11T17:02:40+00:00

+(void)setup { UIImage* spriteSheet = [UIImage imageNamed:@mySpriteSheet.png]; CGRect rect; animation = [NSMutableArray arrayWithCapacity:numberOfFramesInSpriteSheet]; int

  • 0
+(void)setup {
    UIImage* spriteSheet = [UIImage imageNamed:@"mySpriteSheet.png"];
    CGRect rect;
    animation = [NSMutableArray arrayWithCapacity:numberOfFramesInSpriteSheet];
    int frameCount = 0;

    for (int row = 0; row < numberFrameRowsInSpriteSheet; row++) {
        for (int col = 0; col < numberFrameColsInSpriteSheet; col++) {
            frameCount++;
            if (frameCount <= numberOfFramesInSpriteSheet) {
                rect = CGRectMake(col*frameHeight, row*frameWidth, frameHeight, frameWidth);
                [animation addObject:[UIImage imageWithCGImage:CGImageCreateWithImageInRect(spriteSheet.CGImage, rect)] ];
            }
         }
    }
}

Compiled the above code with ARC enabled. The Analyze tool reports a possible memory leak since imageWithCGImage:: returns UIImage with count +1, then reference is lost. Leaks Instrument reports no memory leaks at all. Whats going on here?

Furthermore, since ARC prohibits use of manually using release ect, how does one fix the leak?

Thanks to anyone who can offer any advice.

  • 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-11T17:02:42+00:00Added an answer on June 11, 2026 at 5:02 pm

    ARC does not manage C-types, of which CGImage may be considered. You must release the ref manually when you are finished with CGImageRelease(image);

    +(void)setup {
        UIImage* spriteSheet = [UIImage imageNamed:@"mySpriteSheet.png"];
        CGRect rect;
        animation = [NSMutableArray arrayWithCapacity:numberOfFramesInSpriteSheet];
        int frameCount = 0;
    
        for (int row = 0; row < numberFrameRowsInSpriteSheet; row++) {
            for (int col = 0; col < numberFrameColsInSpriteSheet; col++) {
                frameCount++;
                if (frameCount <= numberOfFramesInSpriteSheet) {
                    rect = CGRectMake(col*frameHeight, row*frameWidth, frameHeight, frameWidth);
                    //store our image ref so we can release it later
                    //The create rule says that any C-interface method with "create" in it's name 
                    //returns a +1 foundation object, which we must release manually.
                    CGImageRef image = CGImageCreateWithImageInRect(spriteSheet.CGImage, rect)
                    //Create a UIImage from our ref.  It is now owned by UIImage, so we may discard it.
                    [animation addObject:[UIImage imageWithCGImage:image]];
                    //Discard the ref.  
                    CGImageRelease(image);
                }
             }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Pjs sketch, which looks as follows: void setup(){ //setup stuff among
I've got a sketch pulled from here : import processing.opengl.*; float a; void setup()
-(void) readProductsFromDatabase { // Setup the database object sqlite3 *database; // Init the animals
I use a NSOpenGLView. - (void)initGL { // Setup OpenGL states [[self openGLContext] makeCurrentContext];
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view
Lets say there is setup like this: public class MyClass { public void DoSomething(string
In my current setup, I have a typedef std::function<void (MyClass&, std::vector<std::string>) MyFunction; std::map<std::string, MyFunction>
i Have two images generated like this - (void)moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve x:(CGFloat)x y:(CGFloat)y
This is my code - (void)updateCounterImage:(NSTimer *)theTimer { static int count = 0; count
this is my code: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup

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.