I have a UI with four Screens (all extending a "main Screen") that users switch between very frequently, at the moment I am switching Screens using g.setScreen(new screen);, but this leads to the problem that I have to reload and initialize everything inside the Screen every single time, which is causing memory leaks.

Is there some way I can save the Screens in memory and just load them without having to re-initialize everything inside them? Or is this bad? Because my current approach is not going to cut it.

I was thinking something like initializing all Screens on startup and saving them in an array, then just loading the Screen I need from that array when I need it, ie g.setScreen(screenArray.get(nextScreen));. Is this a viable approach? Please any advice you can give will help, really need help with this.


1 Answer 1


Maybe setscreen causes a device reset, in which case things get properly nullified. Two suggestions:

  1. Use windowed mode only, then you can place the window in any screen (and for "fullscreen", use a borderless, captionless window with size = physical full screen dimension, place it at any screen's origin).
  2. Render (hidden) everything to a surface first, then copy/draw it to any window in any monitor.

Note however that a device resize also causes a hard reset. But if the monitors have same resolutions, there is no need to resize the device (= the window or the render surface).

  • \$\begingroup\$ Changes things a bit i guess. Maybe mention below your original Q? Perhaps solve something along those directions anyway? A device reset is probably a hard thing regardless of hw. \$\endgroup\$
    – Stormwind
    Commented Apr 15, 2016 at 22:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .