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

  • Home
  • SEARCH
  • 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 8070119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:17:28+00:00 2026-06-05T13:17:28+00:00

I am getting a static analyzer warning about some CGImageRef objects. The warning is

  • 0

I am getting a static analyzer warning about some CGImageRef objects. The warning is “Incorrect decrement of the reference count of an object that is not owned at this point by the caller.” However, I want it to be owned by the caller. Is there some special wording I need to insert into my Obj-C method? When I make a C function to do literally line for line the exact same thing, the warning disappears. The reason I separate them is because sometimes my app uses the CGImage (for editing), and sometimes it uses a UIImage (for setting a UIImageView).

Here is the relevant code (stripped down to its relevant essentials):

+ (UIImage *)imageFromCompressedData:(NSData *)compressedData withSize:(CGSize)size
{    
    CGImageRef cgImage = [SO2CompressionHandler cgImageFromCompressedData:compressedData withSize:size];
    UIImage *returnImage = [UIImage imageWithCGImage:cgImage];
    CGImageRelease(cgImage);

    return returnImage;
}

+ (CGImageRef)cgImageFromCompressedData:(NSData *)compressedData withSize:(CGSize)size
{
    //...decompress data

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)decodedData);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGImageRef outImageRef = CGImageCreate(width, height, 8, 32, 4*width, colorSpace, kCGImageAlphaPremultipliedLast, provider, NULL, false, kCGRenderingIntentDefault);
    CGDataProviderRelease(provider);

    if(CGSizeEqualToSize(CGSizeZero, size) || CGSizeEqualToSize(CGSizeMake(width, height), size))
    {
        CGColorSpaceRelease(colorSpace);
        return outImageRef; //Flagged as potential leak
    }

    //...or resize and return the in a similar way
}

It doesn’t make sense to release the CGImage before I return it right? Then it would just be invalid memory. So is this a hint that I should be using C-functions? Or does the static analyzer simply not check C-functions. I changed cgImageFromCompressedData:withSize: into CGImageCreateWithCompressedData(NSData *compressedData, CGSize size) and like magic, no more warnings. Should I just ignore the warnings, or do they have some merit? Do I have to add the word “new” or “alloc” to my Obj-C method name to make them go away?

  • 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-05T13:17:32+00:00Added an answer on June 5, 2026 at 1:17 pm

    If your method returns a +1 object, its name should start with ‘new’, e.g. newCGImageFromCompressedData:withSize:. This will tell the analyzer that you are deliberately returning a retained object and passing ownership to the caller.

    Alternatively, you can make use of the clang attribute CF_RETURNS_RETAINED by putting this in your method declaration (i.e. in your .h file):

    +(CGImageRef)cgImageFromCompressedData:(NSData *)compressedData
                                  withSize:(CGSize)size CF_RETURNS_RETAINED;
    

    This also tells the analyzer that the method is supposed to returned a retained object, but without having to change the method selector.

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

Sidebar

Related Questions

I'm getting An object reference is required for the non-static field, method, or property
With the latest releases of XCode that contain static analyzers, some of my objects
I'm getting an An object reference is required for the non-static field, method, or
I am getting a warning from the Xcode 3.2.5 static analyser that I don't
I'm getting a potentially leaked object error from the Static Analyzer for this line:
I'm getting exception An object reference is required for the non-static field, method, or
I am getting a coverity static checker tool warning for a piece of code
My serializable class is not getting read in with objectinputstream after adding static methods
I am analyzing Objective-C iPhone project with LLVM/Clang static analyzer. I keep getting two
I'm having some trouble getting a static property through reflection in .NET 4.0. Say

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.