You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, when use DispatchSource(tested Timer and FileSystem) within a do-catch block will break the GCD source.
Consider the code below, it works fine without do-catch block but stop working when the block is present. Since explicitly referencing source inside the eventhandler will solve the program despite nested in do-catch block.
My educational guess is that somehow the do-catch block is breaking the dispatch_retain / dispatch_release cycle.
// main.swift
import Dispatch
do{// remove the try-catch block the timer works fineletsource=DispatchSource.makeTimerSource()
source.setEventHandler{/* uncomment the next line, explicitly reference `source` will resolve the issue as well */// _ = sourceprint("hello world")}
source.scheduleRepeating(deadline:DispatchTime.now(), interval:DispatchTimerInterval.seconds(1))
source.resume()}catch{}dispatchMain()
The text was updated successfully, but these errors were encountered:
Dispatch folks, does a DispatchSource need to be retained while it's active? If so, this pretty much behaves as expected, Yuuji; objects may be released as soon as nothing refers to them anymore. The fact that it works without a do-catch block is mostly a coincidence.
This is a behaves correctly, releasing the last reference on a source is an implicit cancelation. The best way to have it not happen is to indeed have a reference to the source from one of the handler.
calling `cancel` on the source will cause the handler to be destroyed and the retain cycle to be broken.
Environment
OS X 10.12
Additional Detail from JIRA
md5: 13ab7af38c18a6a0a6f154f8ac1b81f0
Issue Description:
Basically, when use DispatchSource(tested Timer and FileSystem) within a do-catch block will break the GCD source.
Consider the code below, it works fine without do-catch block but stop working when the block is present. Since explicitly referencing source inside the eventhandler will solve the program despite nested in do-catch block.
My educational guess is that somehow the do-catch block is breaking the dispatch_retain / dispatch_release cycle.
The text was updated successfully, but these errors were encountered: