FSEventStreamContext
has member variables for functions to retain and release the info
pointer, which in your example is your void *
block pointer.
Via Apple's FSEvents reference:
retain
The callback used retain the info pointer. This can be NULL.
release
The callback used release a retain on the info pointer. This can be NULL.
First, retain. Since you need to cast the block to void *
for FSEventStreamContext
anyway, I think it's fine to continue using CFBridgingRetain()
in your startObserving:
method. No retain callback function is needed.
For release, try this callback function:
void release_callback(const void *info) {
CFBridgingRelease(info);
}
Then try changing your FSEventStreamContext
declaration to:
FSEventStreamContext context = { 0, ptr, NULL, release_callback, NULL };
That should release your block when stopObserving:
is called.