Do I need to manually delete all events to remove my object from memory?

I read on MSDN , which requires Unsubscribing from all events that an object must have in order to manage it from memory. I always used - = to delete all event references inside my object (for example, show MSDN).

Now I have to support the code, and there is a memory leak on it. I see that the previous developer simply installed an object that has all the events, subscribes to it in NULL and does not - = each event method.

Example:

_watcher.Changed += new ...
_watcher.Created += new ...
_watcher.Deleted += ..

//later.

_watcher = NULL;

Is this a good way or saves a variable in memory?

+3
source share
1 answer

_watcher , , .

, .

+6

Source: https://habr.com/ru/post/1728329/


All Articles