8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WindowsFormsHostがメモリリークする問題への対応

Last updated at Posted at 2015-06-05

WindowsFormsHostが動的に作成・削除される状態で、メモリプロファイラーなどで見ると、削除したWindowsFormsHostが解放されずに残ってしまって、メモリリークを起こしていました。
対処法を調べたところ以下の方法で改善しました。

リンク先が消えてしまっても大丈夫なように一応書いておきます。


private void Window_Closed(object sender, EventArgs e)
{
  object winFormsAdapter = typeof(WindowsFormsHost).GetProperty("HostContainerInternal",
    BindingFlags.GetProperty |
    BindingFlags.NonPublic | BindingFlags.Instance).GetValue(host,null);
  if (winFormsAdapter is IDisposable)
   ((IDisposable)winFormsAdapter).Dispose();
  host.Dispose();
}
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?