Skip to content

[Python][C++] Simplify/Validate PyObject refcount in udf.cc #36000

Done

Description

@icexelloss

Describe the bug, including details regarding any error messages, version, and platform.

In udf.cc, there is interaction between C++ and Python where the C++ code holds a user defined Python object inside a Kernel and invoke it over input data.

Due to this interaction, there are a number of Py_INCREF call as well as using OwnRef to manage the refcount for the PyObject (which represents the user defined function. The current code for managing it is either over complicated and/or bug where the C++ code might be over increasing the refcount. While this is not a huge issue (it probably cause the Python function to never be garbage collected), it could use some clean up / documentation as least to improve maintainability.

Appendix:

Component(s)

C++

Activity

  1. thisisnic commented on Nov 25, 2026

    @thisisnic
    Member

    I used an AI agent to check this against current releases, and I've reviewed the results.


    🤖 :

    This looks to have been fixed by #43557 (released in 18.0.0), which removed the extra Py_INCREF calls in udf.cc and added comments on the ones that remain.

    Registering a scalar UDF and calling it 111 times, the reference count of the Python function behaves like this:

    pyarrow After registering After 1, +10, +100 calls
    17.0.0 5 6, 16, 116
    26.0.1 3 3, 3, 3

    So the count no longer grows with each call. Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions