留言板

Vaadin portlet memory leak on handleRenderRequest

Paul Butenko,修改在10 年前。

Vaadin portlet memory leak on handleRenderRequest

Junior Member 帖子: 38 加入日期: 10-7-2 最近的帖子
Hi,
I have made some test with Vaadin portlet which can be reinitialized on handleRenderRequest and faced some strange problem.
Here is code of the portlet:


public class Vaadin_load_portletApplication extends Application {
  Window mainWindow;

  @Override
  public void init() {
    mainWindow = new Window("Vaadin_load_portlet Application");
    Label label = new Label("Hello Vaadin user");
    mainWindow.addComponent(label);

    // set portlet listener, check if application is portlet and init user with listener
    if (getContext() instanceof PortletApplicationContext2) {
      PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext();
      ctx.addPortletListener(this, new CustomListener());
    } else {
      getMainWindow().showNotification("Not inited via Portal!", Notification.TYPE_ERROR_MESSAGE);
    }

    setMainWindow(mainWindow);
  }

  private class CustomListener implements PortletListener {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -6973370282667721257L;

    /** {@inheritDoc}  */
    public void handleRenderRequest(final RenderRequest request,
                                    final RenderResponse response,
                                    final Window window) {
      synchronized (this) {
        if (PortletMode.VIEW.equals(request.getPortletMode())) {

          mainWindow.removeAllComponents();
          System.out.println("removed all components");

          mainWindow.addComponent(new Label("test"));
          System.out.println("added label");

        }
      }
    }

    /** {@inheritDoc}  */

    public void handleActionRequest(final ActionRequest request,
                                    final ActionResponse response,
                                    final Window window) {}

    /** {@inheritDoc}  */

    public void handleEventRequest(final EventRequest request,
                                   final EventResponse response,
                                   final Window window) {}

    /** {@inheritDoc}  */

    public void handleResourceRequest(final ResourceRequest request,
                                      final ResourceResponse response,
                                      final Window window) {

    }
  }
}




As you can see it is pretty simple, on each render request all component from mainWindow removed and new label text added.

I performed some load test of this portlet, which simply open page with portlet 4000 times (100 users with 40 repeated requests)

At the end of test I have analyzed heap dump I faced that instances of Label object is not collected with GC. I think this is not good since in case of lomg term portlet usage out of memory exception will be thrown.

I'm using vaadin 6.7.4 and liferay 6.1.1.

How this can be avoided?

Thanks in advance,
Paul Butenko
thumbnail
David H Nebinger,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
The default version shipped with Liferay is pretty old, you should have the Vaadin control panel, upgrade Vaadin to 6.8.10, recompile the widgetset, and try again.

Honestly, though, this does not represent what I'd code in a Vaadin application. In the init() method you instantiate your objects (even the ones that are not added). In the mode switch code, you swap between the existing components rather than instantiating new ones.

Creating new objects on the fly is just not practical.
Paul Butenko,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Junior Member 帖子: 38 加入日期: 10-7-2 最近的帖子
Yes, I agree, it is not practical.
But if application should totally refresh its state to default. Think, it is easier to create new instance of the view then fully refresh each component to initial state, especially if application has lot of it.

Will try to upgrade vaadin.jar.

Thank you for help.
thumbnail
David H Nebinger,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Each decision to take an easy road comes with side effects...

The problem I believe is that even though all components were removed, that doesn't mean they are not pointed at by some other piece of Vaadin code so they're not candidates for GC.
thumbnail
David H Nebinger,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
I've been doing work with V7 in the portal using the new Navigator/View concept. All of this does not come into play in V6, but basically when a view is activated, the view's enter() method is invoked. I think the basic intent is that this enter() method should reset the component to default values. I tend to use lazy initialization, so in my enter() methods I will create components if they haven't already been created (just doing constructor and setter calls and add to the view), then fall into my 'reset' code.

While I'm glad to see you using Vaadin and glad to help you become successful, there are some oddities such as this that you'll have to be wary of...
Paul Butenko,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Junior Member 帖子: 38 加入日期: 10-7-2 最近的帖子
In my main application I did some reset method for all componentes and it solved problem with memory leak, but still I didn't found the reason why creating and attaching new component to main window does this memory leak.

Thnks for help.
thumbnail
Jack Bakker,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Liferay Master 帖子: 978 加入日期: 10-1-3 最近的帖子
for some use cases ?restartApplication can be added to url to refresh state to default
Paul Butenko,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Junior Member 帖子: 38 加入日期: 10-7-2 最近的帖子
Jack Bakker:
for some use cases ?restartApplication can be added to url to refresh state to default



Yes, In dev env it is Ok, but not in production.
Paul Butenko,修改在10 年前。

RE: Vaadin portlet memory leak on handleRenderRequest

Junior Member 帖子: 38 加入日期: 10-7-2 最近的帖子
Vaadin upgrade didn't helped.
Also I created new thread at vaadin forum - https://vaadin.com/forum#!/thread/3015168