Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
MVP4Vaadin: Limit ViewStack?
I'm using the MVP4Vaadin add-on. Every time a user navigates to a new view, the view (and the view's entire object-graph) is stored in a Stack to enable back-button-functionality and so on.
Every time a user navigates to a view I create a new instance of the view and populate it. This causes the stack to quickly hang on to hundreds of views that cannot be garbage collected even though they will not be used again.
Is there some way to set a limit to the view stack? Or is best practice to keep only one instance of a view per session and then repopulate it every time the uses hits that view?
I would like to not use a navigationcontroller at all but this would cause a lot of refactoring that I cannot afford right now.
Thanks.
So in case anyone is interested, a quick fix was to simply build a NavigationRequest with an empty path. This clears the viewstack on each navigation. Since I don't use the viewstack at the moment this will do for now.
NavigationRequestBuilder.newInstance().startWithEmptyPath().addViewToPath(view).buildRequest()