views:

311

answers:

3

I have a web user control that contains several other (web user) controls and subscribes to events the children raise.

I saw someone somewhere in a similar situation providing Dispose() on the containing control and unregistering the events it had subscribed to.

Isn't it all going to be blown away when the request processing completes? / Is unregistering those events necessary?

A: 

I don't think this is a necessary step.

bashmohandes
A: 

As you say, the page (and all its controls) is recreated on every postback, so it's not necessary

Juan Manuel
+3  A: 

Since the contained controls (event publishers) will no longer be referenced by anything when the containing control itself is no longer referenced, they should be garbage collected. When that happens the containing control can also be garbage collected. Since these objects are all in the same generation, I don't see how the container could be collected any sooner. The unregistering of the event handlers doesn't seem to be necessary. If the event publishers were longer lived objects than the container, then it would make some sense.

For more information, reference this discussion.

tvanfosson