.net - Should you remove the assignment of event to a control -


while talking boss seems extremely knowledgeable .net today, had said should in habit of deleting assignment of event control in designer.

i don't remember exact explanation, recall along lines of the event not being contained within same thread , doesn't cleaned garbage collection? on phone discussion , headset sucks, couldn't hear him recall said

i hoping elaborate, or point me in direction read further?

thanks!

for it's worth, we're using .net 3.5

there's simple rule this. explicitly unsubscribing event required when event source object out-lives event subscriber object.

that's never case in winforms app since form object , components , controls contains die @ same time. form has reference controls through controls collection. control can have reference form through event's delegate object keep form object alive. boss' worry. garbage collector has no trouble circular references this, collects form object @ same time control , event delegate objects.

there few select cases event source object does outlive subscriber object. case application.idle event , systemevents events. notable these events static , keep subscribing object reference life of program, gc cannot help. explicitly unsubscribing these events required when closing form doesn't otherwise terminate app.

if have doubt own code use memory profiler verify assumptions.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -