I understand Objective-C memory management but I’m using Core Graphics functionality such as CGRect, CGPoint, CGImageRef etc.. which is written in plain C.
My question is how do i manage this memory or is it already handled for me? According to the Apple documentation if an Apple Objective-C function doesn’t have copy, new or create in it the returned object is managed for you using autorealease. Is this true for the Core Graphics stuff also? (Well i guess it wont be using autorealease but maybe something similar?)
Thanks for taking the time to read this.
CGRect, CGPoint, etc. are just plain structs, so you can just pass them around by value… you don’t need to allocate them on the heap. However, if you do allocate them on the heap, then you will need to use malloc/free to manage them yourself. Most CoreGraphics functions that return these objects simply return the object (e.g.
CGRect) and not a pointer to them (e.g.CGRect*), so you don’t need to worry about it.