No, thatβs fine, the objects that you pass to your c-method are borrowed, i.e. you do not need to reduce the number of returned objects before returning (in fact, this will be a bad, bad error).
See, for example, this part of the document:
Please note that any links to Python objects provided by the subscriber are borrowed links; Do not reduce their link count!
How do you even determine that you have a memory leak? It is more than likely your problem.
source share