When the Game object is constructed a pre-defined Screen object called TestScreen is assigned to the currentScreen field. TestScreen has a method that generates a new screen like this, where Popup is descended from Screen just as TestScreen is:
private void GeneratePopupScreen(){ Game.ChangeScreen(Popup p = new Popup());}
When this code executes, what lifespan will p have? It's declared and instantiated inside of a method, so it seems like it should have local scope and go out of scope as soon as the GeneratePopupScreen methods ends, which is immediately after the ChangeScreen method ends. But because memory is explicitly allocated on the heap via the new operator, and a reference independent of the GeneratePopupScreen method is assigned p's memory address immediately upon p being instantiated it also seems like maybe p could persist after GeneratePopupScreen ends.
Will p go out of scope once GeneratePopupScreen terminates?







