Wait for all tasks to be stopped and free all allocated resources.
This is mainly used in test suites to ensure proper cleanup of internal data structures.