ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Fix issues found by DPA

Last modified: 21 July 2022

If memory allocation is essential for any program, why does DPA use it as an issue metric? The problem is not in memory allocation, which is very cheap in terms of performance, but in the garbage collection (GC) which may require a lot of system resources. The more memory you allocate, the more you have to collect in the future. For a quick reminder on how .NET manages memory, refer to the JetBrains dotMemory documentation.

But is there anything you can do? From our experience, yes, there are a lot of cases where excessive memory allocation is a result of bad code design. In this chapter, you will find examples of such code design and tips on how you can fix it.

Also, we want to strongly recommend that you use the Heap Allocations Viewer plugin in conjunction with DPA. The plugin highlights all the places in your code where memory is allocated. It's a perfect match for DPA - together they make a perfect couple. While the plugin shows allocations and describes why they happen, DPA shows whether a certain allocation is really an issue.

DPA. Heap Allocations Viewer plugin