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.
I am getting a "Potential leak of an object stored…" on one of my lines. Here is the basic cycle of my code:
CGImageRef renderedRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext());
[_array addObject: (__bridge_transfer id)renderedRef];//_array is an iVar
then somewhere down the road I do this:
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.
Can someone shed some light on this? Also, I have tried just using __bridge but that doesn't make a difference.
Edit 1:
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.
I am not quite clear on when to use the various __bridge casts. Under ARC, does the following increase the reference count?
CGImageRef iRef = (__bridge CGImageRef)array[0];
Also, at some point if I tell my _array iVar to removeAllObjects, will that decrement their reference counts properly?