Vaadin keep the model in memory?

I usingo vaadin with springboot and wanna to know If the vaadin keep the model in memory. beucase I create a lot of models in my project,

Cliente
Cidade
Profissao

When my user enter in my Cliente view I fill a combobox with this models. but in jvm the model only grow-up, even though I’m running the GC the model is not released

17285578.jpeg
17285581.jpeg

The answer is yes and no, I’ll summarize why.

ComboBox and Grid use by default ListDataProvider, which is in-memory DataProvider. If your data model is big, it is not adviced to use the default data provider, since the session footprint potentially will grow oversized.

Therefore it is also possible use lazy data providers. Lazy data provider means a data provider which has custom callbacks to fetch data from database as defined by you. This reduces the memory footprint of your application.

For details how to implement one, check our documentation here: https://vaadin.com/docs/v8/framework/datamodel/datamodel-providers.html, especially the chapter “Lazy Loading Data to a Listing”

We have published also a good blog post, with example app here: https://vaadin.com/blog/lazy-loading-with-vaadin-8

But my problem are when my User leave the view that have a combobox with one of those models, the vaadin don’t release the memory (he keep the models) and if my user back to that view the memory duplicates

I understand now, you are not actually talking about data model, but does Vaadin keep Session or UI in the memory. If application is implemented correctly, Session and UI are not kept in the memory. They should be garbage collected by JVM normally. What is not cleaned are threads started by your application. So application should take care of ensuring that there is no runnaway threads, no references to UI or Session left hanging in threads etc. Those can prevent JVM to garbage collect Sessions and UI instances. Use either UI’s detach() method or sessionDestroyListener as hooks to clean threads etc.

Note, it can take some time before Sessions are GC’d (see: https://stackoverflow.com/questions/51451453/detach-event-in-vaadin-web-app-not-getting-called). If your app consumes memory, you can make clean up happen quicker in various ways. Set session timeout shorter in container. You can set heartbeat interval as short as possible, and set closeIdleSessions=true in your servlet config, something like this:

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyUI.class, heartbeatInterval=5, closeIdleSessions=true, widgetset = "org.myapp.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}

In special cases more tricks may be needed. Then e.g. https://vaadin.com/directory/component/cleanupservlet-add-on can be useful.