gmethvin/directory-watcher

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

lihaoyi opened this issue · 2 comments

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.

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.

Fixed in 0.9.2