java - XSSFWorkbook stays in memory -


i using apache pio version 3.14 export data excel. problem uses lot of memory. visualvm noticed data in oldgen shoots ~80m ~400m 800k export file , stays there. if repeat operation on , on keeps growing. seems xssfworkbook never garbage collected , holds references cells/sheets excel file. tried using sxssfworkbook memory usage similar. there way reduce memory usage? or how can dispose xssfworkbook. tried closing workbook , making reference null, not help

today saw same problem in our application. workbook cells lands in old generation , never deleted. analyze problem created application creates workbook 10 rows each row has 10 cells.

xssfworkbook in main

then tried move code separate thread.

xssfworkbook in runnable

still objects remain in memory workbook, sheet, rows , cells gone. here simplified code sample show how tested it.

public static void main(string[] args) {     runnable runnable = new runnable() {         @override         public void run() {             workbook workbook = null;             fileoutputstream fileoutputstream = null;              try {                 workbook = new xssfworkbook();                 sheet sheet = workbook.createsheet();                 row row = sheet.createrow(0);                 cell cell = row.createcell(0);                 cell.setcellvalue("test");                 fileoutputstream = new fileoutputstream(new file("/tmp/workbook.xlsx"));                 workbook.write(fileoutputstream);             } catch (ioexception e) {                 e.printstacktrace();             } {                 if (workbook != null) {                     try {                         workbook.close();                     } catch (ioexception e) {                         e.printstacktrace();                     }                 }                  if (fileoutputstream != null) {                     try {                         fileoutputstream.close();                     } catch (ioexception e) {                         e.printstacktrace();                     }                 }             }         }     };      thread thread = new thread(runnable);     thread.start();      // infinite loop monitor visualvm     for(;;); } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -