Skip to content

Reference Counting under the Hood (C API) #2540

Answered by rssor
endeav0r asked this question in API
Discussion options

You must be logged in to vote

Generally speaking when we return an object the refcount will already have been increased, meaning you are responsible for freeing it. There are certain exceptions, for example in situations where we return arrays every element in the array has its refcount increased but will be all be decremented when the free function over the entire list gets called.

The other major exception is when receiving object pointers in callbacks, where since the core already holds a refcount you don't need to add/remove references.

The best approach will be to look at what the C++/Python bindings do.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by psifertex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants