How to find the Origin or Source of String duplication values and Sparse array from dotMemory

I am trying to find out the origin / source of duplicate string value in my application but not able to find out it . Can you please help me how to find the origin of string value and how to fix so that it will not come in the next profiling. 

Same issue facing for the sparse arrays , even to anylyze the issue  I create a simple console application and start the dotMemory profiler , now its showing one duplicate string value and some Sparse array. 

Even I had not declared any duplicate string and also not declared or defined any array in my code , even though its showing the duplication string and sparse array in inspection view. 

Can you please help me with this. 

Code used in Console application is : 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(String.Intern("Hello World"));
Console.ReadLine();
}
}
}

Inspection View : 

 

0
5 comments

Hello,

Some objects may be created from system code and you can't affect this behavior, just ignore these objects. In other cases, you can check retention paths and creation stack traces view to find a place in your code where it might be created.

You can open certain strings as an object set by double click on it and open Group by "Similar retention" and "Call tree" view. Also you can open certain string instance from Group by "Instances" view and use "Key retention paths" and "Creation stack trace" view. The same is true for any array in "Sparse arrays" inspection.

Here is additional information about string duplicates inspection:

https://blog.jetbrains.com/dotnet/2015/02/12/string-interning-effective-memory-management-with-dotmemory/

0

Thanks Anna Guseva for your quick reply.

Some objects may be created from system code and you can't affect this behavior, just ignore these objects. 

As per your above reply, in very large application which is developed by some other teams, how should we identify which duplicate string value or object is created from system code and which one is from our  application code ? 

As you suggested I am trying to find the origin/source of string duplicate value ("Voltage") and Sparse Array  ( RawResult[] ) in my application but not able to find out. I want to know the exact location from where this string values and sparse arrays are coming so that I will modify the code and resolve the issue. 

Call tree showing nothing: 

Not able to select FullMode because its disabled whenever i select my running process. by default it select Sample mode.

Please find the uploaded workspace below.

Upload id: 2021_12_28_H85crg3kFEqrNY5y (file: Workspace.dmw)

0

This workspace was created in dotMemory 2021.3.1 but it seems these objects were allocated between the captured samples.

In this case, you should enable "Full" allocations data collecting mode to get stack trace data for each object in snapshot.

 

If you open "Similar Retention" view, you'll see that these strings are retained by "Mcl" and "Channel" class from some not "System" namespace. Is it your code or any third party library which is used by your app?

Anyway, these strings don't take huge amount of memory, you won't improve memory consumption significantly if fix it. Moreover, it can be very difficult to fix if it retained by third party code.

We suggest you to monitor the memory consumption of your service in dynamics on a large amount of data, perhaps then some more tangible problems will appear.

 

 

0

Thanks Anna Guseva for your valuable suggestions,

This workspace was created in dotMemory 2021.3.1 but it seems these objects were allocated between the captured samples. In this case, you should enable "Full" allocations data collecting mode to get stack trace data for each object in snapshot.

My application is Service Fabric based stateless Web Api (.Net Framework 4.8) application and when I  configuring the dotMemory profiler with my application's running process it only allow me to select "Sample" mode the "Full" Mode is always disabled. I am configuring with running process because my application is not a standalone application.

Can you please suggest how can I profile with Full mode with Running Processes.

If you open "Similar Retention" view, you'll see that these strings are retained by "Mcl" and "Channel" class from some not "System" namespace. Is it your code or any third party library which is used by your app?

Yes, its using some third party libraries but below I have one String Duplicate value ("adopter_id") which belongs to one of my application class.

So how would I navigate to the root/source/origin of the duplication string value from here. how should  I find out the class name, variables or properties related with this string value.

Apart from above queries I also want to know few thing about the "Sparse Arrays".

I gone through the JetBrains dotMemory documentions but did not found any documentions, videos and references  to solve the "Sparse Arrays" memory issue.

Its very great full if you please suggest how to resolve the sparse arrays memory issues?

Here I m attaching my latest workspace :

Upload id: 2021_12_29_dzZTWVdMpXWoFcbp (file: Workspace_1.dmw)

Thanks

0

> Can you please suggest how can I profile with Full mode with Running Processes

Full mode isn't available for running processes but you can create new run configuration to profile your application from start. You can use "Windows service" or "Any .NET Process" configuration (don't forget to specified process filters for the second one otherwise the profiler will pick up all new processes). Your service should be restarted in this case.

> So how would I navigate to the root/source/origin of the duplication string value from here. how should  I find out the class name, variables or properties related with this string value.

You can also use retention path presented on your screenshot in the right part of window. As we can see, these strings are exclusively retained by System.Web.Http.HttpServer. In your case the problem is still not significant, but in general there is no universal way to fix such problems. Usually the analysis starts with examining the code of a third-party library and trying to use the library another way. The problem may be in the way of use or in the library itself, a possible solution is to report an error to the developer in second case. This case (just 966B) isn't worth it anyway.

> I gone through the JetBrains dotMemory documentions but did not found any documentions, videos and references  to solve the "Sparse Arrays" memory issue.

There is no such documentation because there is also no universal advice here. In general, these problems are solved by refactoring code where these arrays are created (perhaps using different data structures, manually setting capacity etc.).

We also do not see any significant issues with sparse arrays in new provided workspace.

 

0

Please sign in to leave a comment.