When using forced garbage collection?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
23 views
When you need to force.
GC.Collect();
In what situations/cases, or by what logic it is necessary to use garbage collection?
Or garbage collection is only required when processing large amount of data (for Example, the processing of the polygon pixel with a float, AMI, etc)?
by | 23 views

5 Answers

0 like 0 dislike
this is a series, do not bother, yet really don't run into problems with pauses in garbage collection

then the problem will be the answer to your question

this is NOT a typical situation of use, and that is not possible model recommendations. if a simple explanation is not clear - then you just have to "grow" to their own experiences of different applications

(!) not to be confused with the mandatory release of system resources is usually always stated in the MSDN examples - a system resource (such as a brush when drawing in the forms) must be released. it is not associated with the garbage collector, but due to the fact that the garbage collector does not manage system objects in General
by
0 like 0 dislike
When the garbage collector is not able to produce the garbage collection at the right time or certain conditions.
by
0 like 0 dislike
The call to GC.Collect() is needed for the Assembly of objects in the 1 and 2 generations. The fact that in the 0 generation is going so well. But what is going through the 0-the first generation, i.e. objects in the 1st and 2nd generations, very rarely receive the attention of the collector, if there is no hard pressure on the memory. Thus, very large objects, including arrays, when you create a placed immediately in a heap in the 2nd generation.
Accordingly, you need to match:
1) In the program there is some operation that creates a very large object, so that it immediately falls into the 2nd generation.
2) Free memory on the server is no more, or very little.
3) you Need to avoid down-time associated with garbage collection, when running following such an operation.
4) At some point of the program is similarly to ensure that there is no reference to the large object (otherwise GC will not delete it)
And only then you can pull GC.Collect(). Otherwise, the meaning of cause it is not.
Ie you a hundred percent sure that there will be a delay caused by garbage collection, and exactly what the collector is going to clean the 1st and 2nd generation, but you do not like something when it happens this delay, and you move it to an earlier time (perhaps more appropriate/acceptable) forced call to GC.Collect().
The main thing you need to understand that GC.Collect() magically does not clear the memory. To make this challenge something cleaned you need to be 100% sure that the memory objects are not referenced, but are stuck in memory. In other words, there are no memory leaks. (Yes, Yes, programs on the dot.there also can flow) generally, if you fix the leak, i.e., to build the correct memory, then the need of enforcing the garbage collector will disappear by itself.
by
0 like 0 dislike
In my memory there were two cases:

1. When you use a memory profiler. To see that there remained in the memory.

2. In order to clean the cache objects stored in a WeakReference. To get a list of live objects.
by
0 like 0 dislike
Well basically in methods Dispose (IDisposable implementation)
\rhttps://msdn.microsoft.com/ru-ru/library/system.id...

Perhaps in the destructor yet, but they are considered bad practice in C#
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
5 answers
asked Mar 20, 2019 by kosmonaFFFt
110,608 questions
257,186 answers
0 comments
35,535 users