Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

WPF. Class with finalizer. Memory leak

$
0
0

Continuing the topic
I received fundamentally new data, so I decided to create a separate topic.


Created a minimal reproducing application.

Reproducing conditions:
1) Visual Studio 2017
2) WPF application
3) Launch the application under the debugger
4) WPF window code

using System.Windows;

namespace ReproduceFinalizerMemoryLeak
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            do
            {
                Item item = new Item();
            } while (true);

            InitializeComponent();
        }
    }

    public class Item
    {
        private byte[] _bytes;

        public Item()
        {
            _bytes = new byte[10000];
        }

        ~Item()
        {

        }
    }
}

What comes up:
This application craches with OutOfMemoryException. Item class finalizer is not called.

In my real WPF application, a memory leak occurs without debugging and under milder conditions, but the manifestations are the same: finalizers are not called, memory leaks.

It seems that the WPF main thread blocks the thread in which finalizers are called
under certain conditions.



Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>