releasing memory when scopes end