cancel
Showing results for 
Search instead for 
Did you mean: 

When do subcontroller classes die?

daniel_humberg
Contributor
0 Kudos

I have a question concerning the lifetime of controller class instances.

I have a view called root.bsp, where I create one out of two subcontrollers depending on a variable.


<% IF controller->myVar = 1.%>
    <bsp:call url="c1.do" comp_id = "c1" />
<% ELSE. %>
    <bsp:call url="c2.do" comp_id = "c2" />
<% ENDIF.%>

c1.do has a controller class called CL_1.

At first, myVar is 1, so c1 is called. Now, in CL_1 I set myVar to 2, so in the next request, c2 will be called. I would assume that the instance of CL_1 now will be destroyed because it is not used anymore. However, when I call c1.do later, CL_1 will still have the attribute values from the previous time.

Why is the controller class instance not removed after the corresponding controller/view is not shown anymore?

Accepted Solutions (1)

Accepted Solutions (1)

maximilian_schaufler
Active Contributor
0 Kudos

This has nothing to do whether a controller is used (shown, for the view) or not, but simply if the application is stateless or stateful.

Are you using a stateful application?

Answers (2)

Answers (2)

rainer_liebisch
Contributor
0 Kudos

Hi Daniel,

have a look at the methods of class CL_BSP_CONTROLLER2, there's a method called delete_controller (that's the asnwer to your how-question). You should know by yourself when you want to call it. I don't know the circumstances.

Regards,

Rainer

former_member184313
Participant
0 Kudos

Hi Daniel

Since your application is stateless i'd assume your subcontroller dies with page change (Check Controller method set_lifetime).

Did u try give both controllers the same comp_id? They may overwrite each other this way...

Cheers

Daniel

maximilian_schaufler
Active Contributor
0 Kudos

Hi Daniel 2

how'd you know his application is stateless?

(just out of curiosity)

daniel_humberg
Contributor
0 Kudos

Sorry for the missing information.

My app is STATEFUL.

But statefulness does not mean that all objects have an unlimited lifetime, right? I thought objects are removed by the garbage collector as soon as they are not references anymore...

maximilian_schaufler
Active Contributor
0 Kudos

Well, by making it stateful you explicitly tell the application to not throw away the instances - that's the purpose of statefulness.

(unless I miss out of any technical detail - but the effect stays the same)

daniel_humberg
Contributor
0 Kudos

But then, what's the purpose of specifying the lifetime of the controller. You can chose between "session", "request" or "until page change". I selected the third and I assumed that a page change occured when root.bsp displayed the other controller. But that'S probably not considered a page change, right?

former_member184313
Participant
0 Kudos

sorry daniel, my fault. I meant statefull actually... I was quite sure you used statefull for an MVC application.

sorry for the confusion!

In my opinion, it's not a page change an long as there is no change of the supercontroller.

You could destroy the subcontrollers manually...

cheers

daniel 2

daniel_humberg
Contributor
0 Kudos

>

> You could destroy the subcontrollers manually...

>

How? When?