Fixed memory cleaning of global variables. Issue #3085