none
WPF. Class with finalizer. Memory leak RRS feed

  • Question

  • 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.


    Sunday, June 14, 2020 3:22 PM

All replies

  • Hi Igor Buchelnikov,

    Thank you for posting here.

    Since your application is more related to WPF. you can consider posting your question in new WPF forum for more professional help.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 15, 2020 8:41 AM