#Instantiating all frames vs one at a time with singletons

1 messages · Page 1 of 1 (latest)

quaint valve
#

I have a basic app that opens different jframes such as options, about, all the usual stuff
Is it better to instantiate all these jframes at the same time, set them visible when needed and use HIDE_ON_CLOSE exit operation?
Or would it better to instantiate them with a singleton only when required, then dispose when closing them?

stark siloBOT
#

<@&987246487241105418> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

the beginning of the application or to instantiate them one at a time when needed?

There is no definitive answer to this question as it depends on various factors such as the complexity of the frames, memory usage, and user experience. However, here are some considerations:

  1. Memory Usage: Instantiating all frames at once may consume more memory as all the frames will be loaded into memory even if they are not immediately needed. On the other hand, instantiating them one at a time only when needed can save memory.

  2. Startup Time: If you instantiate all frames at once, it may increase the startup time of your application as it needs to load and initialize all the frames upfront. However, if you instantiate them one at a time when needed, it may slightly increase the loading time of each frame but reduce the overall startup time.

  3. User Experience: Instantiating all frames at once can provide a smoother user experience as there will be no delay when opening a new frame since it is already loaded in memory. On the other hand, instantiating them one at a time may introduce slight delays when opening new frames for the first time.

  4. Complexity: If your frames are simple and lightweight, instantiating them all at once may not have a significant impact on memory or startup time. However, if your frames are complex with heavy resources or dependencies, instantiating them one at a time can help manage resource usage more efficiently.

In conclusion, there is no right or wrong approach here. It depends on your specific requirements and trade-offs between memory usage, startup time, and user experience. You can consider profiling your application's performance and conducting user testing to make an informed decision based on your specific use case.

silk compass
#

Use a JDialog instead of a JFrame for minor options

#

it is made for such

#

I would use lazy initialization, so initialize it when needed