Saving request scope bean reference to session scone bean

G

gallas.robert

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
 
L

Lew

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top