I
Igor R.
Hello,
In my C# project I use a COM-based SDK. Some of its COM objects
generate events.
Assume the following scenario (all the objects below are from the
SDK):
var child = new SDKLib.Child();
child.onSomeEvent += () => { doSomething() };
someParent.setChild(child);
In the above code "child" COM object is held by "someParent" - by
design, preventing it from getting disposed. *But*, IUUC, no one holds
its RCW, because "child" variable is local. So when "child" goes out
of scope, it's GC-ed, which in turn causes it to Unadvise() from the
event source. Thus, after a few seconds "onSomeEvent" stops firing.
Certainly, I can create a List<Object>, which would hold all these
objects - just to prevent their garbage-collection, but maybe there's
a more elegant way to workarnoud this issue?
Thanks.
In my C# project I use a COM-based SDK. Some of its COM objects
generate events.
Assume the following scenario (all the objects below are from the
SDK):
var child = new SDKLib.Child();
child.onSomeEvent += () => { doSomething() };
someParent.setChild(child);
In the above code "child" COM object is held by "someParent" - by
design, preventing it from getting disposed. *But*, IUUC, no one holds
its RCW, because "child" variable is local. So when "child" goes out
of scope, it's GC-ed, which in turn causes it to Unadvise() from the
event source. Thus, after a few seconds "onSomeEvent" stops firing.
Certainly, I can create a List<Object>, which would hold all these
objects - just to prevent their garbage-collection, but maybe there's
a more elegant way to workarnoud this issue?
Thanks.