Tools for checking memory fragmentation [closed]

2019-04-08 01:44发布

问题:

I have recently read topics about memory fragmentation: How to solve Memory Fragmentation and What is memory fragmentation?

I want to see some memory allocation map such as author in these article http://pavlovdotnet.wordpress.com/2007/11/10/memory-fragmentation/

Could you recomend some tools to get memory allocation map like that, so I could see if the memory is fragmented and what is the biggest free space available.

I'm on Windows so I would prefer tools working on this system.

回答1:

Here is a tool that visualizes GC memory and heap usage, also the source code is provided. Another similar app is linked in the comments there as well.

If you need to be able to profile memory usage for a .NET solution, you could check out ANTS Memory Profiler, it can run alongside a project in Visual Studio and keep tabs on how processes and objects are using memory.



回答2:

There is indirect solution to the problem. I have developing server application for a few years. Initially we are doing the allocation on demand and as a result after a running for few weeks the performance of the server degraded. As a workaround we followed this approach -

Suppose you have user defined classes X,Y,Z, .. which you need to allocate from heap at runtime. Allocate n number of objects X at startup. Put all these objects in free pool list. On demand , take each object of x and provide it to your app. When in use, put it in busy pool list. When app wants to release it, put it back to the free pool list. Follow this startegy for Y. Z etc.

Since you are allocating all the needed objects at startup and never releasing back to the OS memory manger until your program exits, you will not face the performance degradation caused by memory fragmentation.