Hi All,
I have been doing some perfomance upgrade on some reports and I have encountered a bug regarding memory allocation.
The issue is the following. When we create a data reference
CREATE DATA <ref> type <whatever type>,
the memory for this reference is allocated. This is of course expected. The problem is that when we do a FREE to this data reference, the allocated memory for this reference remains allocated and there seems to be no way of releasing it whatsoever.
This gets specially dangerous when we create references to structured types since the memory allocated is proportional to the size of the data type.
This happens regardless if the reference is generic or explicit, for example:
R_DATA type ref to DATA.
R_DATA type ref to BKPF.
(I have tried explicitly triggering the garbage collector to ensure memory release.)
I used the debugger’s memory analysis tool to evaluate usage at different points. Total session memory can also be checked at SM04.
For example (this program allocates large amount of data in memory and then tries to release it):
* This structure generates leaks once data ref is created
types: begin of tys_data_leak,
f1(10) type c,
r_DATA type REF TO DATA, “type ref to BKPF shows the same issue
END OF TYS_DATA_LEAK,
tyt_data_leak type STANDARD TABLE OF tys_data_leak.
CLASS lcl_test DEFINITION.
* either with T_DATA as an attribute or as part of the class, same issue
* to check just set or remove r_data from the structure
* once r_data is referenced, there is no way of deallocating the memory
PUBLIC SECTION.
DATA: t_data_leak TYPE tyt_data_leak.
METHODS alloc_mem_leak.
METHODS free_mem_leak.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD alloc_mem_leak.
DATA: ls_data TYPE LINE OF tyt_data_leak.
BREAK-POINT.
DO 100000 TIMES.
ls_data-f1 = ‘AAAAAAAAAA’.
CREATE DATA ls_data-r_data TYPE bkpf. “
INSERT ls_data INTO TABLE t_data_leak.
ENDDO.
ENDMETHOD.
METHOD free_mem_leak.
BREAK-POINT.
*1 Try just freeing the table. nope
*2 Tried individually freeing all references. nope
*3 Tried Freeing the data with FS–>This does not work (and why should it?). nope
*4 Tried freeing the reference (in case of generic) and then replacing it with a new one to a smaller type .nope
LOOP AT t_data_leak ASSIGNING FIELD-SYMBOL(<ls_data>).
CLEAR <ls_data>-r_data.
FREE <ls_data>-r_data.
ENDLOOP.
FREE t_data_leak.
cl_abap_memory_utilities=>do_garbage_collection( ).
COMMIT WORK AND WAIT.”<<unnecesary
ENDMETHOD.
ENDCLASS.
After executing method free_mem_leak memory is still allocated. Memory
This does not happen with non-ref types. (allocated and session memory decreases to the current-used)
Any ideas? I have tried several techniques with no success.
*1 Just freeing the table. nope
*2 Tried individually freeing all references. nope
*3 Tried Freeing the data with FS–>This does not work (and why should it?). nope
*4 Tried freeing the reference (in case of generic) and then replacing it with a new one to a smaller type .nope
Thanks!