Answer the question
In order to leave comments, you need to log in
.NET eats up memory unnecessarily?
Bonsuar, gentlemen!
In general, I have a program that:
byte[] buffer = new byte[1000000000]; // RAM заюзалась
buffer = null;
buffer = new byte[100]; // (<b>GC</b>) тот же самый буфер. Но памяти при этом выделено под 1000000100 байт.
Answer the question
In order to leave comments, you need to log in
It's hard to say anything without seeing the whole code. But here:
byte[] buffer = new byte[1000000000]; // RAM заюзалась
buffer = null;
buffer = new byte[100]; // (<b>GC</b>) тот же самый буфер. Но памяти при этом выделено под 1000000100 байт.
1) compression algorithms use additional. memory for generating dictionaries. The size of the dictionary will depend on both the compression algorithm and the data to be compressed.
2) in order to free memory from a heap of junk - you can do GC.Collect to initialize the garbage collector. In this case, you have to do GC.Collect(2), which is quite an expensive operation.
in addition, you should be aware of the nuances of garbage collection for LOH. Unlike SOH, LOH will not be defragmented in memory, and the CLR will simply try to reuse the freed chunks. Therefore, it is quite possible that there is memory on the heap, but the CLR continues to allocate it for new objects.
The collector will give memory when the program is idle and / or the system needs it (memory) and / or less than some% of the memory is available in the system.
According to the GC call schedule, it was called only at the very beginning.
If you want a different behavior, move the selection and use of the array into a function, and loop the function, while setting gc to have a parallel server assembly. Then the discarded stack frames with a pointer to your old byte[] should be quickly picked up by parallel garbage collection, the application will begin to give away memory more intensively.
Relevant flags in appConfig
https://msdn.microsoft.com/ru-ru/library/ms229357(...
https://msdn.microsoft.com/ru-ru/library/ms229357(...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question