JetBrains Rider 2020.1 Help

Narrowing 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 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.

  • This issue is not mine
    Large solutions include hundreds of projects with many people working on them simultaneously. DPA lets you exclude issues, so that you can leave only issues related to you and your current work.

  • This issue is 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 from issue list

No

Permanently

Method

Mark as fixed

No

Until next run

Method

Increase thresholds

No

Permanently

Solution

Suppressing 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.

To suppress an issue

  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.

Excluding issues

Excluding may be required when you are not interested in a particular issue, for example, if it is not related to your work. As well as suppressed issues, excluded issues are hidden from the Dynamic Program Analysis window and from the editor. The main difference is that you exclude issues only for yourself: The 'excluded' issue state is not propagated to VCS.

To exclude an issue

  1. Open the Dynamic Program Analysis window.

  2. Select the issue, and in the context menu, choose Ignore | Exclude from Issue List.

To return an excluded issue back

  1. Open the Dynamic Program Analysis window.

  2. In the toolbar, in the search field, type %excluded%. This will show you the list of all excluded issues.

  3. Select the issue you want to return back, and in the context menu, choose Ignore | Undo 'Exclude from Issue List'.

Marking 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.

To mark an issue as fixed

  1. Open the Dynamic Program Analysis window.

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

Changing 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

To change issue thresholds

  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: 26 May 2020