GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.11k stars 316 forks source link

Wrap Apple disk refreshing in autorelease pool to avoid system caching #1344

Closed complexspaces closed 2 months ago

complexspaces commented 2 months ago

This PR implements a solution for #1282 by adding an Objective-C autorelease pool around the CoreFoundation FFI calls sysinfo uses to obtain disk information. This was chosen over a tempoary thread because spawning a thread is a much heavier operation (shared memory, stack allocations, etc). It also seems better then a worker thread because longer-lived apps that don't call this operation much might not want an extra thread living forever. In addition to all these approaches, if people are using sysinfo code in a traditional cocoa app then this thread would be extra pointless as the built-in runloops would be clearing autorelease'd values out already.

In the future this pool could be moved to a more reusable context to support multiple refreshes before draining, but this is a performance issue and not a correctness one. Therefore, it is left as future work.

Closes #1282

GuillaumeGomez commented 2 months ago

Just one change but otherwise looks good to me. 👍

GuillaumeGomez commented 2 months ago

Thanks a lot! I'll make a release shortly.