OutOfMemoryException is thrown only at compilation in release

I have a C # Console application that allocates many small objects and arrays. These objects have a short life and are quickly cleaned by the garbage collector. To the question "why do you need to highlight so many short objects of life, you should avoid this": the program is used for the difficult task of AI, and there is no obvious way around this for now.

Here is the problem:

If I run the program in x86 debug mode, it works fine and completes processing in just a few minutes. On average, it uses 300-400 MB.

If I take this same program, but compile it and run it in x86 free mode, the memory used by the program quickly reaches 2 GB (after a few seconds), so it throws OutOfMemoryException(which is the expected behavior, since it is a 32-bit application ) Compiling in x64 release mode does not solve the problem at all, it quickly uses up all the computer's memory (8 GB), and then crashes when the memory fails.

I am using SharpDevelop 4.3.3 to create an application. The only differences between debug and release modes are:

  • Optimize code (release only)
  • Check arithmetic overflow / underflow (debug only)
  • Debugging information: full debugging information (debugging) / lack of debugging information (release)

. -, - . . , (, , ), .

, , , .

+4
2

, , . .

Debug.Assert(), , (: Debug.Assert(List.Remove())).

, Debug.Assert() ( ) , , . , Debug.Assert() .

, - .

+5

, . :

    GC.Collect();
    GC.WaitForPendingFinalizers();

, , . - . , , .

, , - , GC .

, - , , , . .NET, . ( , ). , JetBrains dotMemory. , .

, , . . , .

0

Source: https://habr.com/ru/post/1542381/


All Articles