6

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?

Lilienthal
  • 4,327
  • 13
  • 52
  • 88

2 Answers2

3

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.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • Just one question: will it impact in performance in some way? – Christian Tapia Oct 23 '15 at 14:08
  • 1
    @Christian That depends on whether (and how) you access the tables. A good rule of thumb is - if you access the tables frequently, letting them grow unnecessarily is a bad idea. If you don't access the tables at all - well, why keep the contents in the first place? – vwegert Oct 23 '15 at 16:16
3

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

Nelson Miranda
  • 5,484
  • 5
  • 33
  • 54