|
Re: Static Events Used By Static Classes I've had a quick dig, and the unsubscribe is only doing standard delegate
operations - nothing fancy (unmanaged handles etc). As such, you don't need
to worry about anything here if you are just subscribing a static method to
a static event - it will get cleaned up happily when the process dies.
Static events only normally become an issue when you are listening to them
from instances, i.e.
public class Foo {
public Foo() {
SomeStaticClass.SomeEvent += this.SomeInstanceMethod; // risky
}
// ...
}
because with the above (if not correctly released) the static event can keep
many, many objects alive accidentally. You don't have this problem if you
have a static subscription:
public static class Bar {
static Bar() {
SomeStaticClass.SomeEvent += Bar.SomeStaticMethod; // fine
}
// ...
}
Marc |