chris-zen / coremidi

CoreMIDI library for Rust
https://chris-zen.github.io/coremidi/coremidi/
MIT License
75 stars 20 forks source link

tie lifetimes of ports and client #41

Closed jackdreilly closed 1 year ago

jackdreilly commented 1 year ago

Assign a lifetime to an output port that's tied to the client that creates the port.

This prevents a Client from being dropped while a port is still in use.

Fixes #8

jackdreilly commented 1 year ago

Note that this may be a breaking change for code that was previously dropping the client while the port was still in use. But likely their code doesn't work previously in this event anyways.

jackdreilly commented 1 year ago

I'm going to close this pull request. This strategy works for the case of dropping the Client from scope, but still fails when a Port starts a background process to listen for Midi events.

I've identified the root issue being the tight coupling between Drop'ing Client and Port objects causing the release of the underlying resource in Objective C land.

I'm working on an approach which instead uses reference counting to only release objective c resources when all objects that depend on the objective resource go out of scope.