c# - What happens to Dispatcher.Invoke if the method to be invoked gets garbage collected? -



c# - What happens to Dispatcher.Invoke if the method to be invoked gets garbage collected? -

i have code this:

var mytimer = new timer(500); mytimer.elapsed += (o, a) => { application.current.dispatcher.invoke(() => { // handle elapsed }, dispatcherpriority.render); };

if timer elapses , adds anonymous method dispatcher, goes out of scope , gets garbage collected before dispatcher invokes anonymous method, happen?

it's lifetime won't end because message loop referencing it.

even though object no longer in scope in code, object accessible through rooted object, gc cannot collect it.

the whole point of using managed memory can rely on gc ever reclaim managed resourced when impossible them accessed executable code. if it's possible executable code access object, object not collected.

c# garbage-collection dispatcher

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -