I want to put a conditional breakpoint that will work if the program ate too much memory. I tried to write this in the condition:

GC.GetTotalMemory(false) > 4000000000 

But it turned out that the program just stops working - visually similar to some kind of deadlock. Although, one of the four launches got this:

screenshot

How to make such a breakpoint? Or even simply, how to make VS stop (but not complete) execution when a certain amount of consumed memory is reached?

Just in case, I note that breakpoint is inside the lock-section.

  • And why not use the traditional ways to search for leaks? - KoVadim
  • And at what point is breakpoint? Maybe this is often executable code? Breakpoint conditions are debugged extremely slowly. - VladD
  • @VladD, yes, this is a very often executable piece. Regarding the traditional ways, I would like to know what. The fact is that I process what another program produces and quite understand what the memory goes to (buffering its output if I don’t have enough data to stream it), so I’m interested in what conditions missed a piece of data. And I don’t want to add a code that will support the total buffer size in the dictionary ... - Qwertiy
  • @Qwertiy: Memory profiler? I worked with Ants, quite suitable. Trial version for free. In 2015, Studios seems to have a built-in. - VladD
  • @VladD, I know in which dictionary I crammed the data and I'm interested in its contents. I'm not looking for an unknown memory leak, I'm looking for a bug, because of which, probably, a piece of data is lost, and the next 100 gigs are sent to the buffer. - Qwertiy

1 answer 1

The traditional way with if and an unconditional breakpoint has worked perfectly:

 if (GC.GetTotalMemory(false) > 4000000000) offset = offset; // Тут breakpoint 

PS: But for some reason, after this, the program stopped vyzhirat all 32 gig swapping and began to fit into the traditional 3. o_O

  • Looks like a heisenbag. It seems that every time this method is called, the GC looks and thinks, “Oh, can I clean my memory?” - KoVadim
  • @KoVadim, unlikely ... - Qwertiy
  • It is necessary to watch the logs. In the case of the android, I know for sure that GC writes to the log when it worked. I think that this can be done with .NET. If there is a connection between calling this code and freeing memory, then it is the way it is. - KoVadim
  • @Qwertiy: Then it looks like a race. GetTotalMemory works quite slowly and changes the timings of the code. - VladD