Comments (1)
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)
- Cloning Destination/Source? HOT 4
- Client is not Send HOT 9
- Notifications callback not called when devices are added or removed
- SIGILL in Tests on macOS 10.14
- Serious safety problems with callbacks HOT 1
- CoreFoundation objects over-released in Properties
- Undefined Behavior in `Client` and `Properties`
- Use the block crate and functions that take blocks instead of boxing callbacks. HOT 4
- Is Human Readable midi data support HOT 1
- Issue receiving midi packets when using CoreMIDI with Tauri HOT 5
- MIDIClientDispose causes trouble on iOS HOT 1
- Handle MIDIGetDestination/MIDIGetSource failure
- Why not use MIDIPacketListAdd? HOT 5
- Client can be dropped while port is open HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coremidi.