gmethvin / directory-watcher

A cross-platform Java recursive directory watcher, with a JNA macOS watcher and Scala better-files integration
Apache License 2.0
265 stars 34 forks source link

close() doesn't properly cleanup OS-X fsevent streams #31

Closed lihaoyi closed 5 years ago

lihaoyi commented 5 years ago

It seems you're calling CFRunLoopStop and CFRunLoopStop, but according to https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005289?language=objc you also need to call FSEventStreamUnscheduleFromRunLoop, FSEventStreamInvalidate, and FSEventStreamRelease. Not sure what the consequence is of not calling those, but I suppose it's best practice to do so. Probably leaking some small amount of memory if we don't.

gmethvin commented 5 years ago

Good catch. Based on the documentation, it looks like we need to call CFRunLoopStop, then FSEventStreamInvalidate, then FSEventStreamRelease. FSEventStreamInvalidate will automatically unschedule from all run loops. Seems like if we don't we might leak memory or file descriptors.

gmethvin commented 5 years ago

Fixed in 0.9.2