Having switched from VBA to VB.NET (on Visual Studio), I'm encoutering a bizarre behavior of termination of temporary bodies. When I run a VB.NET script that creates temporary bodies, and at the end, set the pointers to Nothing and let the script complete itself, it disposes of all temporary bodies in the model. However, if at any point of debugging my script, I terminate it prematurely (Shift+F5, or if it encounter any error and stops by itself), the temporary bodies remain in the model, and I am unable to dispose of them. The script is terminated, all pointers should be gone, but the temporary bodies are still visible. Rebuilding, redrawing model doesn't help. Even closing Visual Studio doesn't clear these bodies. The only thing that helps is closing and re-opening the model itself. It would appear that SolidWorks latches onto these temporary bodies, and they become completely independent of Visual Studio.
I tried calling GC.Collect(), GraphicsRedraw2() and other functions at the start of my script, so it would clear out the temporary bodies of the previous debug, but it doesn't help either.
I'm sure the solution is dead simple here, but I am unable to find it. Is there some API function to call at the beginning of my script to clear all temporary bodies that remain from previous debugs?