简体   繁体   中英

C#: List all variables in a log file, along with their memory usage

I am working on a C# service project which is a TCP server. When I start my service, its memory usage goes around 40 MB , but as the time passes, it doubles - triples its memory usage. I know that C# is garbage collected and all, but there is some problem with the application.

I am using Log4net in my application and I am using Entity framework to store data in database and tcpServer to manage my incoming data.

Is there a way to list all the memory variables in RAM, sorted by size in descending order in a log file? Or, Is there a better way to debug such problems (like real-time analysis)?

You can try with windbg

 !dumpheap -stat

as described here and here

Looking at the columns in the output, MT stands for Method Table and is basically a pointer to the table that describes that type of object. Count is the number of objects that exist in the heap of the given type. TotalSize is the amount of memory that is being consumed by any one type of object. The last column is obviously the fully typed name of the object.

Consider also SOSNet , an open source C# project, that analyzes the output from the command line version of WinDBG, to display data in a better way. You can also display the list of all .Net types loaded in memory with their "Total Size". 在此处输入图片说明

Generally speaking, there can be many causes, maybe you are leaking threads, is there only one thread accepting all the connections?

Otherwise you can take and analyse memory snapshots of your process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM