Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A use case where singleton can be bad even for the stateless object

While working on TestAutomation, we introduced spring IoC and had a look at PageObjects, there are totally stateless so why dont' let just make 'em singleton?

IMO it will burden unecessary memory requirements on JVM, but given today's machine where we usaually have many GB of RAM I am not sure how significant can be the impact.

Let's say we have 100 pageObjects, if 20 instance create a load of 1 MB, 100 will create 5 MB.

If you are using singleton for before the test spring has to load the 10MB, although it will be one time cost due to context-caching

Ultimately 5 MB is small cost but still does it make sense to make such niche object singleton? pageObjects are just like DTOs or pojos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment