<p>When is this called? More specifically, I have a control I'm creating - how can I release handles when the window is closed. In normal win32 I'd do it during <code>wm_close</code> - is <code>DestroyHandle</code> the .net equivalent?</p>

<hr>

<p>I don't want to destroy the window handle myself - my control is listening for events on another object and when my control is destroyed, I want to stop listening to those events. Eg:</p>

<pre><code>void Dispose(bool disposing) {
    otherObject.Event -= myEventHandler;
}
</code></pre>

[{'answer_id': 43499, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': '<p>Normally <code>DestroyHandle</code> is being called in <code>Dispose</code> method. So you need to make sure that all controls are disposed to avoid resource leaks.</p>\n'}, {'answer_id': 43560, 'author': 'dan gibson', 'author_id': 4495, 'author_profile': 'https://Stackoverflow.com/users/4495', 'pm_score': 2, 'selected': False, 'text': "<p><code>Dispose</code> does call <code>DestroyHandle</code>, but not always. If I close the parent window, then Windows will destroy all child windows. In this situation <code>Dispose</code> won't call <code>DestroyHandle</code> (since it is already destroyed). In other words, <code>DestroyHandle</code> is called to destroy the window, it is not called when the window is destroyed.</p>\n\n<p>The solution is to override either <code>OnHandleDestroyed</code>, or <code>Dispose</code>. I'm opting for <code>Dispose</code>.</p>\n"}]
['https://Stackoverflow.com/questions/43490', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4495/']