JetBrains Rider 2021.2 Help

Narrow down DPA scope

There are a number of cases when you may want to exclude certain issues from the DPA issue list.

For example:

This is not an issue

All programs require memory. A method may sometimes allocate a lot of memory - not because of bad code design, but just because this is required by the current use case. If these are just a few methods, the best solution is to suppress these issues. If you get a lot of false positives, then probably it is better to increase the memory allocation threshold.

You are not an owner of this code or not interested in analyzing it now

Large solutions include hundreds of projects with many people working on them simultaneously. DPA lets you exclude particular parts of a solution from analysis, so that you can leave only issues related to your current work.

This issue has been already fixed

A rare case when you have already fixed the issue but have not run/debug the solution one more time. If you want such an issue to be hidden from the list, you can mark the issue as fixed.

Short summary:

Shared through VCS

Hides issue until

Granularity

Suppress

Yes

Permanently

Method

Exclude

No

Permanently

Process, module, class, method

Mark as fixed

No

Until next run

Method

Increase thresholds

No

Permanently

Solution

Suppress issues

To suppress an issue, you must mark the corresponding method with the SuppressMessage attribute. The main benefit of suppressing the issue is that the attribute is set in the source code, so, it can be shared through VCS. The easiest way to set the attribute is to use a context action.

  1. In the editor, find the method you want to suppress. Note that the SuppressMessage attribute makes DPA ignore memory allocations not only in the method itself but in all child calls as well.

  2. Put the caret at the line highlighted by DPA and press Alt+Enter.

  3. In the context action list, choose Suppress memory allocation issues and then choose what exactly you want to suppress in the current call subtree: only the selected issue, all issues of this type, or all issues.

    DPA. Suppress issue

You can set the SuppressMessage attribute manually. For example:

[SuppressMessage("ReSharper.DPA", checkId: "DPA0002: Excessive memory allocations in SOH", MessageId = "type: Sudoku.Cell")] public Cell Copy() => new Cell(Number, _options);

Here:

  • "ReSharper.DPA" is the required attribute category.

  • checkId specifies what issue type must be suppressed (description is optional):

    • "DPA0001: Memory allocation issues": any memory allocation issues.

    • "DPA0002: Excessive memory allocations in SOH": allocations to the small object heap.

    • "DPA0003: Excessive memory allocations in LOH": allocations to the large objects heap.

    • "DPA0004: Closure object allocation": allocations because of closures.

  • MessageId: lets you to narrow the attribute's scope by allocation size and/or type. You should set the scope filter using a list of key-value pairs: "key1: value1; key2: value2; ..." The following keys are available:

    • type: EXACT_FQN: suppress issues where the objects of the specified type are allocated. EXACT_FQN is the type full name, including namespace and all substitutions of generic types.

    • size: VALUE "B"|"KB"|"MB"|"GB"|"TB": suppress issues if the total size of allocated objects is less than VALUE.

    For example: "type: System.Object; type: System.String; size: 500MB"

    This filter means that DPA must suppress all issues related to allocations of objects of the System.Object or System.String types, unless the total size of allocated objects is less than 500MB.

Exclude code from analysis

Excluding may be required when you are not interested in analyzing a particular part of the code, for example, if it is not related to your current work. You can exclude particular processes, modules, classes, and methods: The related issues will be hidden from the Dynamic Program Analysis window and from the editor. Note that you exclude code only for yourself: The excluded issues are not propagated to VCS.

Exclude code from Dynamic Program Analysis

  1. Open Settings | Build, Execution, Deployment | Dynamic Program Analysis | Filtering.

  2. In Filters, click Add filter Add ... next to the required filter rule:

    • Analyze code only in: Specify a process, a module, a class, and/or a method to be included in the dynamic analysis. All other code items will be excluded. Code items are filtered independently on one another. For example, you can specify a method and leave asterisks * for a module and a class to include only methods with the specified name from all modules and all classes.

    • Do not analyze code in: Specify a process, a module, a class, and/or a method to be excluded from the dynamic analysis. Code items are filtered independently on one another.

Mark issues as fixed

Marking an issue as fixed is similar to excluding. The main difference is that excluding is permanent while 'marking as fixed' hides the issue until you run/debug your solution: If the issue was not in fact fixed, DPA will return it back to the issue list.

  1. Open the Dynamic Program Analysis window.

  2. Select the issue, and press Delete or choose Ignore | Mark as Fixed in the context menu.

Change issue thresholds

DPA marks a method as an issue only if it allocates memory above the threshold value. Therefore, the easiest way to get rid of false positives is to increase the corresponding threshold. Note that there is no universal threshold: Depending on the current execution context, your application can allocate different amount of memory. For example, the size of the data your app works with can change from run to run.

You can set a threshold for each issue type in the Thresholds tab of the Dynamic Program Analysis window. The default thresholds are:

  • Closure object: 50MB

  • Large Object Heap: 50MB

  • Small Object Heap: 100MB

  1. Open the Dynamic Program Analysis window.

  2. Do one of the following:

    • Select the issue which is above the current threshold, and in the context menu, choose Ignore | Set New Threshold for .... This will set the corresponding threshold right above the issue allocation value.

    • Switch to the Thresholds tab and set a new threshold value for the desired issue type.

Last modified: 16 November 2021