App.DoIdle() and GC.Collect() in VB.Net 2010 and ST4

Jun 19, 2012 at 10:35 PM

You may be faced with a situation where you will need to call both App.DoIdle() and GC.Collect. I ran into this recently.

After making some changes to a frame assembly, the macro removes the panels (since many of them are no longer appropriately sized), analyzes the new conditions, and places panels on the frame as appropriate.

During this process, the macro checks to see if any of the existing panels in the folder are of the correct size as needed and it uses these panels and only makes new one as necessary. Once all the needed panels are placed on the frame, the macro then deletes any unused panels in the folder to reduce the space used on the file server.

The problem is, when a panel is deleted from the assembly, it is not immediately released by SE and also not immediately released by the OS. Calling App.DoIdle() will tell SE to release the object and then, calling GC.Collect() will tell the OS to release the file. Then the macro can delete the unused files.

If you try to use GC.Collect() by itself, it will likely not work since SE still has a hold on the object. If you try to use App.DoIdle() by itself, it will likely not work since the OS does not release the files just because SE no longer has a hold on them but waits for an "indeterminate" time before doing so. Using both calls in the order stated is the method that has worked for me.