Using static objects and singleton good idea for memory?

Hi , i ve seen all samples of vaadin recreating same Label , Resources all the time per user.
It makes bad garbage collection usage as i think…

And if user count increase many GC operations will exists.

Its good to use static Label and Button if used all for all people.

A component can be attached to one parent only and cannot be used in multiple applications so you should not use static Labels, Buttons or other components.

Is there any way to reduce garbage collections?
No way to tune?

Have you actually profiled garbage collection in such an application?

What I assume you are thinking about is labels that you actually add to layouts.They do leave the eden space of the young generation (assuming an Oracle HotSpot JVM), but I believe in at least 99% of applications the GC cost of these would be negligible compared to the rest of the load on the system - they are just a drop in an ocean compared to all the other allocations and CPU use in the application server and in your own application.

If you are thinking about “transient” labels from e.g. table field factories, these rarely leave the eden space and are therefore very cheap to GC.

In any case, most Vaadin applications have at most perhaps some hundreds of labels stored in the session of a user, and the number of concurrent users of a Vaadin application is typically in the hundreds or thousands, not millions. Do remember that Vaadin is good for developing rich web applications, less so for traditional web sites - although
Vaadin can scale
.

If you are storing thousands of labels in a container or putting them in a layout for every user
and
have a massive number of users
and
do see a significant cost when profiling, the solution is probably a small (or larger) redesign of the affected parts of your application. In that situation, armed with more details, people on the forum can probably help more.