Home >Backend Development >C++ >When is it Acceptable to Call GC.Collect()?
The timing of using GC.Collect carefully
Although it is not recommended to directly call
, in some specific cases, this is reasonable. For example, when the service runs in a circular manner and is in a free state after performing the task for a long time, forced garbage recovery during the free stage to release the memory occupied by the failure, which can optimize the resource utilization rate.
GC.Collect()
Another acceptable situation is after the large window is turned off in the GUI application. At this time, all UI controls meet the condition of garbage recycling, and the short -term performance decrease during the closing of the window may not notice, so it is reasonable to start GC collection.
In addition, the following situations may also need to consider calling
:
GC.Collect()
GCLatencyMode.LowLatency
for compulsory execution complete GC. GCLatencyMode.SustainedLowLatency
GC.Collect(2, GCCollectionMode.Forced)
Use .NET 4.6, you can use the GC.TryStartNoGCRegion
The above is the detailed content of When is it Acceptable to Call GC.Collect()?. For more information, please follow other related articles on the PHP Chinese website!