Fixed unused thread-internal contexts not being freed until the application exits.