Saving request scope bean reference to session scone bean

Discussion in 'Java' started by gallas.robert@gmail.com, Mar 19, 2008.

  1. Guest

    Hi,

    Maybe dump question.

    What happens when reqest scope bean reference is set in some field of
    session scoped bean. Normally at the end of the request request scope
    bean should be discarded by Garbage Collector.

    What I deduct is that since reference to reqest scope bean exists in
    session bean, request scope bean will not be discarded. However after
    next request web container will create new request scope bean and old
    one will be invalid. Until I save reference to new request scope bean
    in session bean. Old one will be not discarded by Garbage collector
    even if from web container point of view this objct is invalid.

    Is this correct?

    Robert
    , Mar 19, 2008
    #1
    1. Advertising

  2. Lew Guest

    wrote:
    > Maybe dump question.
    >
    > What happens when reqest scope bean reference is set in some field of
    > session scoped bean. Normally at the end of the request request scope
    > bean should be discarded by Garbage Collector.
    >
    > What I deduct [sic] is that since reference to reqest scope bean exists in
    > session bean, request scope bean will not be discarded. However after
    > next request web container will create new request scope bean and old
    > one will be invalid. Until I save reference to new request scope bean
    > in session bean. Old one will be not discarded by Garbage collector
    > even if from web container point of view this objct is invalid.
    >
    > Is this correct?


    I expect not, but I'm interested in the evidence for your deduction.

    Does the object hold a circular reference to the request instance?

    Unless something live refers to the request, then it becomes unreachable at
    the end of the servlet service() method. It should go away in an upcoming GC.

    As for object X, request-lived objects ("scope" is a compile-time term;
    runtime deals with lifecycles) also go away - /unless/ there's a live
    reference to them somewhere else, in your case from a session-lived object.
    References don't flow "upstream", so nothing keeps the request alive unless X
    itself does.

    R -->\
    S --> X

    When the "R" arrow breaks, the "S" arrow keeps X alive. No one is holding on
    to R after service() exits.

    --
    Lew
    Lew, Mar 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. madhu
    Replies:
    2
    Views:
    6,181
    Sudsy
    Jul 23, 2003
  2. David Thielen
    Replies:
    2
    Views:
    772
    Marek Lange
    Sep 12, 2003
  3. X3
    Replies:
    0
    Views:
    408
  4. Replies:
    0
    Views:
    446
  5. Francesco
    Replies:
    3
    Views:
    456
Loading...

Share This Page