.NET WinForm Memory Consumption

前端 未结 3 1247
小蘑菇
小蘑菇 2020-12-21 15:36

I\'ve been profiling a WinForm\'s application using \".NET Memory Profiler\".

I can\'t quite seem to understand how my application is growing to 1GB, then 2GB, then

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 16:12

    Is this a known issue for VB.NET apps?

    Yes. It is a side-effect of Edit + Continue support compiled into the executable. It is affected by any event that is declared with the WithEvents keyword. A WeakReference keeps track of those event instances. Problem is, those WeakReferences are leaked if you run the app without a debugger. The rate at which the process consumes memory is highly dependent on how many instances of the class get created. The leak is 16 bytes per event per object.

    The workaround is simple, do not use the Debug build of your app without a debugger. Only use the Release build. And of course, only ship the Release build to your customer.

提交回复
热议问题