1 Reply Latest reply on Dec 5, 2008 1:48 PM by Nick Belaevski

    Number of View Root in Session increase Session Size ( memmo

    Faraz Kazmi Newbie

      I am getting problem of session size increase due to multiple viewroots caching by AjaxStateManager.

      By ( see below code ) default it saves 16 x 16 map of view roots in session. i.e. 16 versions of 16 different view roots of different pages. Which obviously makes session heavy.

      In my case most of the binded data lies in View Root Attributes. So after every request session size increases which causes memory problem.

      Any suggestion how to solve this problem??


      protected SerializedView saveStateInSession(FacesContext context,
      Object treeStructure, Object state) {
      SerializedView serializedView;
      UIViewRoot viewRoot = context.getViewRoot();
      ExternalContext externalContext = context.getExternalContext();
      Object session = externalContext.getSession(true);
      synchronized (session) {
      SynchronizedStateHolder viewStates = (SynchronizedStateHolder) externalContext.getSessionMap().get(
      VIEW_STATES_MAP);
      if (null == viewStates) {
      viewStates = new SynchronizedStateHolder(new LRUMap(getNumberOfViews(externalContext)));
      externalContext.getSessionMap()
      .put(VIEW_STATES_MAP, viewStates);
      }

      synchronized (viewStates) {
      Object id = getNextViewId(context);
      LRUMap stateMap = viewStates.getStateMap();
      LRUMap logicalViewsMap = (LRUMap) stateMap.get(viewRoot
      .getViewId());
      if (null == logicalViewsMap) {
      logicalViewsMap = new LRUMap(getNumberOfViews(externalContext));
      }
      // Renew last seen view.
      stateMap.put(viewRoot.getViewId(), logicalViewsMap);
      logicalViewsMap.put(id, new Object[] { treeStructure, state });
      serializedView = new SerializedView(id, null);
      }
      }


      return serializedView;
      }