Skip to content

add finaliser on native objects with deinit() #2464

@dhalbert

Description

@dhalbert

Currently most native objects don't use m_new_obj_with_finaliser(), which marks the object as having __del__() to call when the object is gc'd. Only network.socket and audiobusio.I2SOut currently do this, and I'm adding another use in _bleio.

audiobusio.I2SOut.__del__() just called its deinit(), which seems like a good idea. We could do the same for other objects with deinit(), like busio.*, etc. This would free up pins when their holding objects were gc'd.

I'm not sure this has a lot of practical value, because if you want reuse a pin, you should call deinit() on its holding object immediately, but it would make a gc.collect() free up pins if the holding objects were gc'd. Otherwise the pins would just stay allocated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions