flex - Whould the function be garbage collected before evaluating? -
i have function in class:
private function fireitemcreated(data: bytearray): void { settimeout(function(): void { var event: itemcreatedevent = new itemcreatedevent(data); dispatchevent(event); }, 1000); }
this function called dispatch item created event when image thumbnail created.
but delays event on time prevent user interface freezes. , i'm guessing happen if garbage collector executes after fireitemcreated function call before timer event. closure removed or stays until executed?
it can't happen.
if function called settimeout
called. function-object passed settimeout
creates strong closure-binding linked execution context , all settimeout
callback functions protected (strongly held) host engine (imagine there invisible var timeouts = []
can't access). wouldn't fun if timers magically swallowed evil grime captain.
good question , happy coding.
the issue described can happen in other languages , implementations of timers. see .net's threading.timer class , notes.
Comments
Post a Comment