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

The Archive Base Latest Questions

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

I have a question on how to handle a CGImageRef as a synthesized property

  • 0

I have a question on how to handle a CGImageRef as a synthesized property of a class.
If I define an CGImageRef with

@property (nonatomic, retain) CGImageRef image;

then the compiler complains that “retain” cannot be used here. If I leave out the retain, then I assume “assign” is used instead, and I need to do the retain myself when I set the property:

self.image = CGImageRetain ( cgimage );

then I get an “Potential leak” warning when running Analyze. Can I safely ignore this warning? Or does the synthesize code do an implicit CGRetain anyways, even though no “retain” is specified in the property definition?

  • 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-27T03:03:23+00:00Added an answer on May 27, 2026 at 3:03 am

    What you want to do is add an annotation to the property that the type really can be retained.

    Change the property declaration to

    @property (nonatomic, retain) CGImageRef image __attribute__((NSObject));
    

    Note that this will only generate the getters and setters for you, the instance variable itself is not ARC controlled. Specifically, this means that you must release it in dealloc, and that you need to use proper retain and release when assigning directly to the instance variable.


    A better approach may be to use a typedef:

    typedef CGImageRef CGImageObject __attribute__((NSObject));
    @property (nonatomic, retain) CGImageObject image;
    

    In this case, the instance variable is controlled by ARC, and so you must not release it in dealloc, and direct assignments to the instance variable are handled by ARC as well.


    For reference, see the specification, specifically section 4.1.1:

    Applying __attribute__((NSObject)) to a property not of retainable
    object pointer type has the same behavior it does outside of ARC: it
    requires the property type to be some sort of pointer and permits the
    use of modifiers other than assign. These modifiers only affect the
    synthesized getter and setter; direct accesses to the ivar (even if
    synthesized) still have primitive semantics, and the value in the ivar
    will not be automatically released during deallocation.

    and section 3:

    A retainable object pointer (or “retainable pointer”) is a value of a
    retainable object pointer type (“retainable type”). There are three
    kinds of retainable object pointer types:

    • block pointers (formed by applying the caret (^) declarator sigil to a
      function type)
    • Objective-C object pointers (id, Class, NSFoo*, etc.)
    • typedefs marked with __attribute__((NSObject))
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UI question that troubled me on the best method to handle
I have a question about how should I handle image files of various sizes
I have a question regarding using Semaphores HANDLE WINAPI CreateSemaphore(...); Is there anyway I
I have followed the suggestion in this question... [ How to handle checkboxes in
just a general question, do you ALWAYS have to handle error? i was just
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have a question about PHP Class. I am trying to get the result
I have a question that is related to possible overhead of ExecutorService s in
i have a question that is more design and architecture related. I am coming
I have a question about entity creations that is specific to a student information

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.