Why use CGImageRef not CGImage instead?

2.5k views Asked by At

I'm a new one to the media layer and the photo layer ,and what makes me confused is that there a lot of objects like CGImageRef and CMSampleBufferRef ,and I don't know why apple let us use objects like "XXXRef" not objects like "XXX"? I know there must be some reasons but I don't know,can anyone tell me why ?


update: I mean ,why apple want us to us CGImageRef instead of we create the Ref ourselves like CGImage *theCGImage ?

1

There are 1 answers

2
Sergii Martynenko Jr On BEST ANSWER

Actually, you should ask Core Foundation authors about it =)

CGImage is a C-struct. It means, that it is being copied each time passed as a parameter or return value. Or, even, being assigned to some variable. I imagine that something like CGImage is reeeeealy large thing. So, simply passing a pointer to it is much better idea.

The real reasons behind this decision was, I believe, much more complicated and have something to do with reference counter, bridging between CF and Foundation objects, etc