C # Memory Exception - Warning Strategy

Inside a complex multi-threaded application, I remove the exceptions from memory, perhaps once a week. The application sends / reads massive amounts of data through several sockets, where the read data is cached to avoid overflow of the network interface buffer.
What is the best memory exception analysis strategy? During normal operation, the application is displayed with a size of "Total bytes in all heaps" of up to 1.5 gigabytes in the Process Explorer.
Maybe the strategy is that the thread that polls either

GC.GetTotalMemory ()

or

PrivateMemorySize64 ()

once a second to know when to start analyzing things? I have not yet studied commercial profilers, and I am a little concerned about their impact on performance, which may also give incorrect results regarding the actual analysis of problems.

+8
c # out-of-memory
source share
4 answers

Your memory is probably fragmented from numerous string operations or other operations that create and free small blocks of memory, such as boxing / unpacking.

You will get this exception when the CLR cannot allocate a sufficiently large free block of memory.

I use the "CLR Profiler" and check the memory allocation. If you see numerous white spots (free blocks) and large free blocks, you need to start watching how you select objects.

For example, before assigning one line to another, make sure that the lines are different first. Using StringBuilder is all cases that eliminate boxing and other memory optimizations.

I use this technique and completely eliminate exceptions, with the exception of a known issue with binary de-serialization.

Recover the lost art of memory optimization in managed code http://msdn.microsoft.com/en-us/magazine/cc163856.aspx

Studying memory problems http://msdn.microsoft.com/en-us/magazine/cc163528.aspx

Performance optimization in Visual Basic.NET at http://msdn.microsoft.com/en-us/library/aa289513 (v = vs .71) .aspx

+3
source share

You might want to install debugging tools for windows and use adplus

ADPlus.vbs (ADPlus) is a Microsoft Product Support Services (PSS) tool that can fix any process or application that stops responding (hangs) or crashes (crash).

Basically, you can establish that you are watching the application, and when it crashes, it will capture a dump, which you can then analyze using WinDBG / SOS.

+1
source share

You can use MemoryFailPoint to try to give you some guarantees for a given operation.

But I recommend isolating the process your application runs in by switching to the 64-bit version, and you may need to reduce some performance to give you a reasonable guarantee for the use of your memory.

+1
source share

How about using weak links for caching? clicky

0
source share

All Articles