T
T
Tsiren Naimanov2018-04-29 12:34:15
C++ / C#
Tsiren Naimanov, 2018-04-29 12:34:15

When do you use forced garbage collection?

When it is necessary to force it
GC.Collect();
In what situations/cases or according to what logic is it necessary to use garbage collection?
Or is garbage collection necessary only after processing a large amount of data (For example, processing a polygon pixel by pixel with floats, etc.)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
#
#, 2018-04-29
@ImmortalCAT

this is from a series - do not bother until you really run into problems, with pauses for garbage collection,
then the problem itself will be the answer to your question,
these are NOT typical application situations, therefore typical recommendations are not possible. if simple explanations are not clear, then you just need to "grow" to them with your own experience of various applications
(!) should not be confused with the mandatory release of system resources - this is usually always noted in MSDN examples - some system resource (such as a brush when drawing in forms) must be sure to be released. it's not related to the garbage collector, but because the garbage collector doesn't manage system objects at all

A
Alexander Yudakov, 2018-04-29
@AlexanderYudakov

There were two cases in my memory:
1. When using memory-profiler. To see what's left in memory.
2. To clear the cache of objects stored in WeakReference. To get a list of live objects.

D
Dmitry Bashinsky, 2018-04-29
@BashkaMen

Well, mostly in Dispose methods (an implementation of IDisposable)
https://msdn.microsoft.com/en-us/library/system.id...
Maybe in destructors, but they are considered bad practice in C#

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question