The basics of reference counting for allocated struct 'objects' seem pretty straightforward to me: Give new objects a RC of 1; On assignment decrement the RC (and free if RC=0) of the old object and increment the RC of the assigned object; Decrement the RC of all objects leaving scope.

However i'm a bit puzzled about what i need to do when RC'ed objects are passed to / returned from functions. Do i have to inc/dec the RC before/after each function call and where should the inc's and dec's be put if they are necessary (at the start & end inside the function or before & after the function call?)? What about RC'ed objects returned by a function?