Yes I meant exactly the same. I made the reference to workbook pointing to null but it seems the objects do not get collected by GC !!! I meant maybe there is some king of method that we should call on workbook like release or close which releases all the resources.
-----Original Message----- From: Amol Deshmukh [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 03, 2005 1:00 PM To: 'POI Users List' Subject: RE: how should we release the memory I'm not sure what you mean by "release the memory", since in Java you cannot decide in a deterministic fashion when the garbage collector will be invoked. But you can make the resources used by your workbook /eligible/ for garbage collection by ensuring that there are no references to the workbook after you are done with it. You can ensure this by either reusing the reference or setting it to null (at the same time ensuring that you dont have any "saved" references elsewhere like in a ArrayList or Map etc.) Beyond this you can use a memory profiler to see that object allocation actually reduces after you remove all references to the workbook instance. ~ amol > -----Original Message----- > From: Firouz Bharthania [mailto:[EMAIL PROTECTED] > Sent: Tuesday, May 03, 2005 2:23 PM > To: [email protected] > Subject: how should we release the memory > > > Hi, > > > > It seems that the memory does not get released after the > excel document is > created and written into the file!!! > > I highly appreciate is anybody can help me with this issue. > > Here it is the code I used to create the document. > > > > >public class ExcelWriter { > > > > > > protected String file = null; > > > > > > protected FileOutputStream fileOut = null; > > > > > > protected HSSFWorkbook wb = new HSSFWorkbook(); > > > > > > protected HSSFSheet sheet = wb.createSheet("new sheet"); > > > > > > > > > > > > HSSFCellStyle dateCellStyle = wb.createCellStyle(); > > > > > > HSSFCellStyle timeCellStyle = wb.createCellStyle(); > > > > > > HSSFCellStyle decimalCellStyle = wb.createCellStyle(); > > > > > > HSSFCellStyle currencyCellStyle = wb.createCellStyle(); > > > > > > HSSFCellStyle stringCellStyle = wb.createCellStyle(); > > > > > > HSSFFont cellFont = wb.createFont(); > > > > > > > > > > > > > > > > > > > > > > > > public void close() throws IOException { > > > > > > try { > > > > > > wb.write(fileOut); > > > > > > fileOut.close(); > > > > > > }catch(Exception e) { > > > > > > e.printStackTrace(); > > > > > > } > > > > > > } > > > > > > > > > > > > public ExcelWriter(String file) throws IOException{ > > > > > > this.file = file; > > > > > > fileOut = new FileOutputStream(file); > > > > > > > > >currencyCellStyle.setDataFormat(HSSFDataFormat.getBuiltinForm > at("0.00") > > >); > > > > > > > > >decimalCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0")); > > > > > > > > >dateCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(" > m/d/yy")); > > > > > > > > >timeCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("h:mm > > >AM/PM")); > > > > > > cellFont.setFontHeightInPoints((short)10); > > > > > > cellFont.setFontName("Courier New"); > > > > > > currencyCellStyle.setFont(cellFont); > > > > > > decimalCellStyle.setFont(cellFont); > > > > > > stringCellStyle.setFont(cellFont); > > > > > > dateCellStyle.setFont(cellFont); > > > > > > timeCellStyle.setFont(cellFont); > > > > > > } > > > > > > > > > > > > > > > > > > protected HSSFCell createNewCell(int row, int column) { > > > > > > HSSFRow sheetRow = null; > > > > > > if((sheetRow = sheet.getRow(row)) == null) { > > > > > > sheetRow = sheet.createRow((short)row); > > > > > > } > > > > > > HSSFCell cell = sheetRow.createCell((short)column); > > > > > > return cell; > > > > > > } > > > > > > > > > > > > public void writeString(String string, int row, int > column) throws > > >IOException{ > > > > > > HSSFCell cell = createNewCell(row, column); > > > > > > cell.setCellValue(string); > > > > > > cell.setCellStyle(stringCellStyle); > > > > > > } > > > > > > > > > > > > public void writeTimestamp(java.util.Date date, int row, int > > >column) throws IOException{ > > > > > > HSSFCell cell = createNewCell(row, column); > > > > > > cell.setCellValue(date); > > > > > > cell.setCellStyle(dateCellStyle); > > > > > > } > > > > > > > > > > > > public void writeNumber(BigDecimal value, int row, int column) > > >throws IOException{ > > > > > > HSSFCell cell = createNewCell(row, column); > > > > > > cell.setCellValue(value.doubleValue()); > > > > > > cell.setCellStyle(currencyCellStyle); > > > > > > } > > > > > >} > > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
