Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
895 views
in Technique[技术] by (71.8m points)

vb.net - .NET WinForm Memory Consumption

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 3GB of usage - according to windows task manager.

The private bytes using that tool, and "Total Bytes in All Heaps" shows only as 70MB or so. At the top of my list of instances hanging around, they are mostly String, or WeakReferences to lots of little objects.

All the application is doing is showing a form that loads data from a database. I repeat the show/dispose cycle of the form about 100 times and the growth is continuous.

I've tried about 3 memory profiling tools now and none of them are showing me where this enormous amount of memory consumption is coming from.

Can anyone help or take a guess as to what it might be?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...