Execute cleanup code when the workbench command is deactivated

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Alexander Stepaniuk
Posts: 4
Joined: Sun Jan 15, 2017 11:04 am

Execute cleanup code when the workbench command is deactivated

Post by Alexander Stepaniuk »

Hi,

What is the right approach for handling command deactivation?

There seem to be different situations in FreeCAD when command can be deactivated:
- Command can be cancelled
- Command can be interrupted due to another command started
- Command can finish the work
- Probably some other situations...

When command is being deactivated, it is a good time to free some resources, acquired by the command. Like: event callbacks, selectionObserver, temporary objects.
How to write commands properly to avoid situations when some resources leak?

Many thanks :)
Post Reply