vendredi 27 février 2015

Is it OK to run GC.Collect in a background thread?

Following this SO answer, I'm doing:



ThreadPool.QueueUserWorkItem(
delegate
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
});


My goal is to do a garbage collection run after I close a large WinForms form with lots of images/PictureBox controls to ensure I have no images in memory anymore. (I do believe I follow the instructions of Jon Skeet).


I'm doing it in a background thread in order to try to have my UI responsive.


My question:


Does it bring me any benefits to do the garbage collection in a background thread? Or does it actually make my application slower/hang longer?


Aucun commentaire:

Enregistrer un commentaire