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.
then tried move code separate thread.
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
Post a Comment