Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP object into a loop - performance would be better by using a clear ?

yasz
Explorer
0 Kudos

Hello

We are managing our data into a loop by creating some objects.

In order to improve the performance of the report, will a CLEAR statement improve the performance of the memory management and the performance of the report?

AS IS

loop at lt assigning (<lfs>)

data(lr1) = cast cl_...(<lfs>).

data(lr2) = lr1.->get_TOTO()

....

....

endloop

TO BE

loop

data(lr1) = cast cl_...(<lfs>).

data(lr2) = lr1.->get_TOTO()

...

...

CLEAR: lr1, lr2...

endloop

Please imagine the instantiation of 10 objects during each loop.

Will the performance be improved?

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

That's a weird question. Why do you think a CLEAR would help improve the performance? SAP never does that (in mainstream software at least).

yasz
Explorer
0 Kudos

Hello

I am thinking about memory and garbage collector management.

BR

0 Kudos

Hi,

Efficient memory management is essential for optimal performance.

I would try to utilize LOOP AT <itab> REFERENCE INTO <ref_obj> syntax, if it really works for specific scenario. This would avoid your Field symbol assignment and later type casting to another object reference. However, considering lesser visibility on what complete loop does, you can always make your own decisions on how to proceed.

Thanks.

Sandra_Rossi
Active Contributor
0 Kudos

Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

I was worried about abap instantiation management in a user session and the garbage collector,

I was worried if some issues could happen with too many instantiations and I was thinking if a systematic clear of useless instantiation could help in enduser session memory management.

Many thanks for your answers.

Sandra_Rossi
Active Contributor
0 Kudos

Based on your input, CLEAR is useless.

If your question is about garbage collection, how often it runs and so on, you may look at the ABAP documentation. It should be generally sufficient. If you experience a high memory consumption because the garbage collection doesn't run at the right time, you may invoke the garbage collection explicitly.