Thanks for looking into it. The reason this is happening is that you created a COM object and then closed it while it was still in use by MSScriptControl.ScriptControl. This causes MSScriptControl.ScriptControl to attempt to modify/free memory, allocated by mIRC, that no longer exists, corrupting mIRC's memory pool.
One way around this would be for mIRC to prevent you from using /comclose on an active COM connection. However, users have in the past asked to be able to /comclose an active connection. Whether this causes an issue depends on the COM object. It is up to the scripter to determine whether this is something that can be done with the COM object that they are using.