2


I have opened a large excel file as a Apache POI workbook (using VM args to set max memory size)

After successfully opening the file, I read the required data and finished my work.

Now I want to continue further in the programming with other tasks but before I do that I want to make sure I free up the memory used up the workbook.

I checked the API doc but there is nothing like workbook.close().

Can someone suggest what's the right way to free up the memory taken up by the workbook?

Jeril Nadar
  • 175
  • 3
  • 10

3 Answers3

2

I believe you just need to let the objects go out of scope and let the GC do its work. You might also want to consider using the streaming POI framework since that uses less memory.

Streaming Workbook

John B
  • 32,493
  • 6
  • 77
  • 98
  • Yes. Also, more likely if the close method would exist, it won't try to free the allocated memory. The best way to clean up unused memory in java is to eliminate obsolete references (see effective java 2nd edition) . – zeller Nov 14 '11 at 19:19
  • I tried by forcing GC to clean up the memory even after I closed the workbook. However this did not change memory foot print and when I tried to relocate memory for another workbook and process it at some point I got outOfMemory exception from JVM. – theo231022 May 09 '17 at 07:53
0

Workbook.close() is supported at least in the latest version and does exactly that link for apache poi maven

theo231022
  • 329
  • 2
  • 12
0

From the javadoc it seems that you only need to let go of your handle to the workbook it will be garbage collected.

Roger Lindsjö
  • 11,330
  • 1
  • 42
  • 53