Clean up shared resources immediately as the last context is destroyed.