Skip to content

[BUG]: leaked types and functions in python 3.12 #397

@Yikai-Liao

Description

@Yikai-Liao

Problem description

I'm writing an open source midi parsing library symusic.

We previously use pybind11 as the binding framework, and switch to nanobind for better performance in the last update.

Owing to their silimar interface, I switch to nanobind easily, without changing much of the code. And pybind11 just worked well with those binding codes.

And here is the current binding codes.

However, I get tons of leak errors today when just importing the new version of library in a python script.

nanobind: leaked 56 types!
 - leaked type "symusic.core.KeySignatureSecondList"
 - leaked type "symusic.core.TextMetaTick"
 - leaked type "symusic.core.KeySignatureQuarter"
 - leaked type "symusic.core.ScoreTick"
 - leaked type "symusic.core.PitchBendQuarterList"
 - leaked type "symusic.core.ScoreQuarter"
 - leaked type "symusic.core.TempoTick"
 - leaked type "symusic.core.TextMetaQuarter"
 - leaked type "symusic.core.TextMetaQuarterList"
 - leaked type "symusic.core.PedalQuarter"
 - leaked type "symusic.core.TimeSignatureTick"
 - ... skipped remainder
nanobind: leaked 1276 functions!
 - leaked function "__getstate__"
 - leaked function "__deepcopy__"
 - leaked function "__bool__"
 - leaked function ""
 - leaked function "clear"
 - leaked function "__repr__"
 - leaked function "__bool__"
 - leaked function "__bool__"
 - leaked function ""
 - leaked function "count"
 - leaked function "__contains__"
 - ... skipped remainder
nanobind: this is likely caused by a reference counting issue in the binding code.

This problem would only occur in script, not in ipython.
Since we have upload this version to pypi, it is easy to reproduce:
pip install symusic==0.3.0

Reproducible example code

import symusic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions