WPF memory leak

前端 未结 6 1962
生来不讨喜
生来不讨喜 2021-01-13 00:35

I have a simple wpf application. In main window i have stack panel and 2 buttons. First button adds 100 my user controls (without any data bindings, events, bitmaps), and se

6条回答
  •  暖寄归人
    2021-01-13 01:17

    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    

    This is a surefire way of forcing non-GCable objects into Gen2 prematurely, thus increasing your memory footprint for a longer period of time, for no good reason.

    As Aliostad said: don't!

提交回复
热议问题