Reply to: Close xmetal with multiple documents openDecember 16, 2013 at 10:37 pm
I believe the general answer is that you need to make sure to release all COM objects you have instantiated and not rely on garbage collection to do that. Seems you understand this already and are just trying to figure out your own logic to do that. Tough one.
It sounds to me like you made some assumptions about when they need to be released and that you will need to change your logic so they can be released sooner. If they are being instantiated at a global variable level then you might have more flexibility on when you can release them. Just make sure that your release code always runs. If they are instantiated at the local level then you will want to release them as soon as they are no longer needed. That might mean they are instantiated and then released more often than in your original design.
One more thing: Be careful when modifying toolbars. Toolbar buttons should only be added or removed in the events named “On_Default_CommandBars_Complete” (for app-level/all-dtd changes) and “On_CommandBars_Load_Complete” (for dtd-specific commandbars). Direct toolbar modifications during other event macros are not supported. You can modify whether a macro is enabled or pushed in, which in turn affects whether a toolbar button (and or menu item) is greyed out or pushed in. You do this using DisableMacro() and PushInMacro() inside the On_Update_UI event. Don't try to make direct changes to the buttons themselves that mimic this behaviour.