Coder Social home page Coder Social logo

Comments (1)

chris-zen avatar chris-zen commented on June 15, 2024

Hi @sourcebox, thanks for the report.

I've been investigating it a bit. Apparently the Drop for Client is working fine and the client is disposed at CoreMIDI level.

With this code:

impl Drop for Client {
    fn drop(&mut self) {
        println!("Dropping client ...");
        let status = unsafe { MIDIClientDispose(self.object.0) };
        println!("{}", status);
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        let mut counter = 0;
        loop {
            let client = Client::new("test midi client");
            counter += 1;

            match client.as_ref() {
                Ok(client) => {
                    println!("{}, {:?}", counter, client);
                }
                Err(error) => {
                    println!("{:?}", error);
                    break;
                }
            }

            std::thread::sleep(std::time::Duration::from_millis(1000));
        }
    }
}

I see this:

1, Client { object: Object(bc29041), callback: BoxedCallback(0x0) }
Dropping client ...
0
2, Client { object: Object(bc29042), callback: BoxedCallback(0x0) }
Dropping client ...
0
3, Client { object: Object(bc29043), callback: BoxedCallback(0x0) }
Dropping client ...
0
4, Client { object: Object(bc29044), callback: BoxedCallback(0x0) }
Dropping client ...
0
5, Client { object: Object(bc29045), callback: BoxedCallback(0x0) }
Dropping client ...
0
6, Client { object: Object(bc29046), callback: BoxedCallback(0x0) }
Dropping client ...
0
7, Client { object: Object(bc29047), callback: BoxedCallback(0x0) }
Dropping client ...
0
8, Client { object: Object(bc29048), callback: BoxedCallback(0x0) }
Dropping client ...
0
-50

But reading the docs I just found a possible cause for the problem that it would be out of my control:

https://developer.apple.com/documentation/coremidi/1495335-midiclientdispose#discussion

Don’t explicitly dispose of your client; the system automatically disposes all clients when an app terminates.
However, if you call this method to dispose the last or only client owned by an app,
the MIDI server may exit if there are no other clients remaining in the system.
If this occurs, all subsequent calls by your app to MIDIClientCreate(_:_:_:_:) and MIDIClientCreateWithBlock(_:_:_:) fail.

So apparently, clients are not supposed to be created and destroyed that frequently, but instead live for the whole lifecycle of your app.

from coremidi.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.