Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrect way to handle CGImageRef in containers under ARC
    primarykey
    data
    text
    <p>I am new to incorporating arc in my projects. I am trying to understand __bridge and its little friends so that I can properly cast my CGImageRef's when adding and removing them from containers. </p> <p>I am getting a "Potential leak of an object stored…" on one of my lines. Here is the basic cycle of my code: </p> <pre><code>CGImageRef renderedRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext()); [_array addObject: (__bridge_transfer id)renderedRef];//_array is an iVar </code></pre> <p>then somewhere down the road I do this:</p> <pre><code> CGImageRef iRef = (__bridge_retained CGImageRef)array[0]; //then I do something fancy with iRef //at the end of the method, I get "Potential leak of an object stored…" //I have no idea what to do //I've tried CGImageRelease(iRef); but it still doesn't change the warning. </code></pre> <p>Can someone shed some light on this? Also, I have tried just using __bridge but that doesn't make a difference.</p> <p><strong>Edit 1:</strong></p> <p>I expanded the analyzer results and followed what was happening. It was because I was using iRef in a method like so: [self doSomethingFancy:iRef]; and in that method, iRef was being retained but not released. So that fixes the warning, but I'm still a bit puzzled.</p> <p>I am not quite clear on when to use the various __bridge casts. Under ARC, does the following increase the reference count?</p> <pre><code>CGImageRef iRef = (__bridge CGImageRef)array[0]; </code></pre> <p>Also, at some point if I tell my _array iVar to removeAllObjects, will that decrement their reference counts properly? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload