When I'm loading massive amounts of data into memory in the form of internal tables (hundreds of thousands or even millions), should I manually clean up entries by refreshing the internal tables as soon as I'm done with them?
I assume that these variables will be cleaned up automatically once they leave scope (i.e. the program ends, a class instance is freed, ...). But if I'm dealing with long-running batch programs, does it make sense to free up these temporary tables?
Will doing so increase performance in any noticeable way? Or is the only reason for doing this to avoid running into the memory limits?
It does make sense to release unused memory, especially if there's an obvious place in the code to do so. It is easy if you can simply leave the scope (method) and have the system throw away all local variables automatically. Even if you only avoid running into memory limits, that's already worthwhile - plus, you're making life easier for all other users of the system.
You are right, when leaving a subroutine or method the variables are going to be cleaned.
I think that refreshing tables is a good practice, in fact I do it most of the time, however, when dealing with big amount of data I use FREE instead of REFRESH.
From this link:
To ensure that the table itself has been initialized, you can use the statement
REFRESH itab.
This always applies to the body of the table. With REFRESH, too, the initial memory requirement fort he table remains reserved.
To release this memory space, use the statement
FREE itab.
You can use FREE to directly initialize an internal table and to release its entire memory space, including the initial memory requirement, without first using the REFRESH or CLEAR statements. Like REFRESH, FREEaccesses the table body, not the table work area. After a FREEstatement, the internal table still exists. It still occupies the amount of memory required for its header (currently 256 bytes). When you refill the table, the system has to allocate new memory space to the lines.
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With