Narrow 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 |
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.
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.Put the caret at the line highlighted by DPA and press Alt+Enter.
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.
You can set the SuppressMessage
attribute manually. For example:
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 thanVALUE
.
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
orSystem.String
types, unless the total size of allocated objects is less than 500MB.
Exclude 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.
Exclude an issue
Open the Dynamic Program Analysis window.
Select the issue, and in the context menu, choose Ignore | Exclude from Issue List.
Return an excluded issue back
Open the Dynamic Program Analysis window.
In the toolbar, in the search field, type
%excluded%
. This will show you the list of all excluded issues.Select the issue you want to return back, and in the context menu, choose Ignore | Undo 'Exclude from Issue List'.
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.
Open the Dynamic Program Analysis window.
Select the issue, and in the context menu, choose Ignore | Mark as Fixed.
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
Open the Dynamic Program Analysis window.
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.