Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 2.0.0-RC1
    • Fix Version/s: unscheduled
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1,351

      Description

      Possible unconfirmed error reported on the forums:

      I have a managed bean that needs to remove its data listener from an
      ApplicationScoped data model, and I would like to put the managed bean in View
      scope. So I need to know when its lifespan is up.

      I naively thought that ViewScoped managed beans expire when I change to a
      different page in the browser, but I see that it's not so simple. If I then use
      the browser's back (or forward) button the view is still there, maintaining its
      state. I was also a little surprised to see that the ViewScoped bean survives
      destroying the session.

      Anyway, I put a method with a @PreDestroy annotation on the ViewScoped bean, and
      also registered a ComponentSystemEventListener on the view root for
      PreDestroyViewMap events.

      In the server logs, I see it create new instances of my bean when I reload the
      page or follow a link to it, but I have never seen either the PreDestroy method
      or the listener called. (The PostConstruct method DOES get called).

      Am I confused, is there a bug, or do they just live forever? Or is there another
      way to find out when they expire? Is it possible to have more than one
      UIViewRoot on the same page concurrently in one session? What triggers their
      expiration? I haven't found much detail on this, so if anyone knows of any doc,
      please let me know.

      Here's my code for registering the listener. I tried calling it in the bean's
      constructor and in the PostConstruct method, which does get called.

      private void registerViewListener() {

      FacesContext context = FacesContext.getCurrentInstance();
      UIViewRoot viewRoot = context.getViewRoot();
      viewRoot.subscribeToEvent(PreDestroyViewMapEvent.class, new ViewMapExitHandler());
      }

      public class ViewMapExitHandler
      implements ComponentSystemEventListener, Serializable {

      public ViewMapExitHandler() {}

      public void processEvent (ComponentSystemEvent event) {

      System.out.println("ViewMapExitHandler");
      diagram.setDataModel(null);
      event.getComponent().unsubscribeFromEvent(PreDestroyViewMapEvent.class, this);
      }
      }

      Thanks for any help.

        Activity

        Show
        driscoll added a comment - Forum thread: http://forums.java.net/jive/thread.jspa?threadID=67603&tstart=0
        Hide
        Ryan Lubke added a comment -

        Assigned.

        Show
        Ryan Lubke added a comment - Assigned.
        Hide
        driscoll added a comment -

        Created an attachment (id=1030)
        Zip of working Netbeans project

        Show
        driscoll added a comment - Created an attachment (id=1030) Zip of working Netbeans project
        Hide
        judys added a comment -

        Thx for the project code, I see now what's happening.

        If you exit the page with an <h:command link, it calls the bean's PreDestroy
        method. If you exit any other way, like <a href= or reload the page or type
        something into the browser's location bar and load that, then it doesn't call
        the PreDestroy method. I haven't tried killing the session yet.

        I think in my case I would run the risk of accumulating dead diagrams which
        can't be displayed and can't be garbage collected because the data model still
        has refs to their listeners, and that would be a problem.

        Show
        judys added a comment - Thx for the project code, I see now what's happening. If you exit the page with an <h:command link, it calls the bean's PreDestroy method. If you exit any other way, like <a href= or reload the page or type something into the browser's location bar and load that, then it doesn't call the PreDestroy method. I haven't tried killing the session yet. I think in my case I would run the risk of accumulating dead diagrams which can't be displayed and can't be garbage collected because the data model still has refs to their listeners, and that would be a problem.
        Hide
        driscoll added a comment -

        I talked with Ryan and Ed about this, and here's what they said, paraphrased.

        Essentially, this is expected behavior.

        Imagine a case where you have multiple tabs open, or press the back button - in
        both cases, under the case where you're doing a GET, you'd expect the state to
        be there - otherwise, you'll get a ViewExpiredException.

        This means that if you also do <h:link> this will also be the behavior.

        The views will all be reaped when the session expires, of course, which is often
        set to 30 or 60 minutes.

        There's also a configurable limit to the number of views - 15 is the default,
        and it's a LRU (Least Recently Used) queue.

        Ed Burns had said when I asked this that he'd also like to think about this
        further. I'll leave this open for today awaiting his input. However, I'm
        changing the milestone to TBD, while the bug is open.

        Sorry it took so many iterations for you to get your answer, but I'm afraid that
        this is going to be closed as not a bug. If you have specific questions about
        other ways to reduce memory consumption, we should probably discuss them on the
        forum.

        Show
        driscoll added a comment - I talked with Ryan and Ed about this, and here's what they said, paraphrased. Essentially, this is expected behavior. Imagine a case where you have multiple tabs open, or press the back button - in both cases, under the case where you're doing a GET, you'd expect the state to be there - otherwise, you'll get a ViewExpiredException. This means that if you also do <h:link> this will also be the behavior. The views will all be reaped when the session expires, of course, which is often set to 30 or 60 minutes. There's also a configurable limit to the number of views - 15 is the default, and it's a LRU (Least Recently Used) queue. Ed Burns had said when I asked this that he'd also like to think about this further. I'll leave this open for today awaiting his input. However, I'm changing the milestone to TBD, while the bug is open. Sorry it took so many iterations for you to get your answer, but I'm afraid that this is going to be closed as not a bug. If you have specific questions about other ways to reduce memory consumption, we should probably discuss them on the forum.
        Hide
        driscoll added a comment -

        Closing, as per previous comments.

        Show
        driscoll added a comment - Closing, as per previous comments.
        Hide
        Manfred Riem added a comment -

        Closing resolved issue out

        Show
        Manfred Riem added a comment - Closing resolved issue out

          People

          • Assignee:
            driscoll
            Reporter:
            driscoll
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: