Hi Milli
       i am very happy to see that u solve ur problem and thx for this gr8
information ,i think it surly help us in future.

Vyom Tiwari


----- Original Message ----- 
From: "Mili Aggarwal, Noida" <[EMAIL PROTECTED]>
To: "POI Users List" <[email protected]>
Sent: Friday, April 08, 2005 9:59 AM
Subject: RE: out of memory.


> Hey Vyom,Thanks for the help I sorted it out...Actually the memory was
> leaking due t non-closure of  a prepared Statement but there are some
GREAT
> Java lessons that I learnt which I thought I must share with you guys:
>
>
>
> 1) Whenever coding that requires DB connectivity do remember do double
check
> that all your DBConnections,PreparedStatements,ResultSet are properly
> closed.
>
> 2) If passing an object to a method, make sure you assign the object=null
> once you are through with the method. It wont affect the original object
as
> in Java objects are not passed by reference...
>
>
>
> I know it's a POI forum but I thought why not share some Java intricacies.
>
>
>
> 3) I came across a tool that detects memory leak and tells what all
objects
> are present in memory. It can really help someone to optimize the code. It
> comes with BEA's Jrockit. Try it out. Its awesome.
>
>
>
> http://e-docs.bea.com/wljrockit/docs142/userguide/memleak.html
> <http://e-docs.bea.com/wljrockit/docs142/userguide/memleak.html>
>
>
>
> (I am not working for BEA ;-) )
>
>
>
> 4) Another article of interest that I came up with is:
>
> setupSet-up: optimized Java JVM configuration
> Application Developer is written in JavaTM, which poses some configuration
> questions. The IBM (r) and Sun Java JVMs have default configurations
> suitable for a wide range of Java applications. Their initial heap size is
4
> MB, with a maximum equal to half of all the physical memory on your
machine.
> Therefore, because Java applications cannot grow past the maximum heap
size,
> they do not automatically consume a lot of memory, and can increase in
size
> without consuming all of your memory.
>
> If you use Application Developer to develop and test a large number of
> complex programs, you may need to adjust your maximum heap size. To get an
> estimate of the appropriate heap size:
>
> 1.        Determine the size of your physical memory (for example, 640
MB).
>
> 2.        Subtract the amount of memory used for your operating system
(for
> example, 210 MB).
>
> 3.        Subtract the amount of memory used for typical concurrent tasks
> (for example, if the machine is primarily used for Application Developer,
> subtract 100 MB).
>
> 4.        Tip: The number of KB of memory used by your operating system
and
> your active tasks is shown in the Windows Task Manager in the bottom
> right-hand window (in our example, it would say Mem Usage: 310,000 KB).
>
> The total memory remaining will help you determine the appropriate maximum
> heap size. In our example, it is 640 - 310 = 330 MB.
>
> Now the tradeoffs. If you make your maximum heap too small, you'll run out
> of memory when building large applications. If you make it too large (or
run
> too many concurrent applications), then parts of Application Developer
will
> continuously swap in and out, causing an apparent system "hang" when
> swapping back in. If you make your initial heap too small, you'll slow
> startup as memory is continuously grabbed in pieces. If you make the
initial
> heap too large, you'll prevent unused memory from being available to other
> system tasks. Also, remember that the actual running Java program
> (Application Developer) requires memory in addition to its data heap. So
> consider a maximum heap of 2/3 of your available memory as calculated
above,
> and an initial heap of about 2/3 of that maximum heap. (The maximum heap
is
> the critical piece; the initial heap is just a startup optimization.)
Also,
> for major applications, you might even chose to set your initial heap
equal
> to the maximum heap (as is often recommended for server applications). In
> our example with 330MB of available memory, you could make your maximum
heap
> 250 MB and your initial heap 150 MB. When Java objects are released, the
> memory is not freed until "garbage collection" takes place. When the heap
is
> initially used up, garbage collection will walk through all old objects
and
> finally free the memory for reuse, causing an apparent "hang" during this
> processing. It may be better to be aggressive in regular garbage
collection
> rather than letting it build up and result in a long collection. The
default
> minimum free starting collection is 30% and the default maximum free
> stopping collection is 60%, but we really don't have enough experience yet
> to recommend changing the defaults.
>
> You can customize the Application Developer configuration using parameters
> with the startup program (wsappdev.exe). For example:
>
>
> wsappdev.exe -data MyWorkspace
>   -vmargs -Xmx250m -Xms150m -Xminf0.40 -Xmaxf0.60
>
>
>
>
>
>
>
> 4)Another code optimizations that one can do with POI is:
>
>
>
> POI Optimization - eliminating trailing empty rows from an HSSFSheet.
>
>
> While my spreadsheet has only 7 rows with data, POI creates over 65,000
rows
> in the HSSFSheet object. This leads to a large amount of essentially
unused
> memory. In order to free that memory, the following code snippet from my
> version of the public HSSFWorkbook(POIFSFileSystem fs, boolean
> preserveNodes) method works from bottom towards the top of the sheet
> removing empty rows. The code in bold performs the optimization.
>
>             HSSFSheet hsheet = new HSSFSheet(workbook, sheet);
>
>
>
>             boolean stop = false;
>
>             boolean nonBlankRowFound;
>
>             short c;
>
>             HSSFRow lastRow = null;
>
>             HSSFCell cell = null;
>
>
>
>             while (stop == false) {
>
>                 nonBlankRowFound = false;
>
>                 lastRow = hsheet.getRow(hsheet.getLastRowNum());
>
>                 for (c = lastRow.getFirstCellNum(); c <=
> lastRow.getLastCellNum(); c++) {
>
>                     cell = lastRow.getCell(c);
>
>                     if (cell != null && lastRow.getCell(c).getCellType()
!=
> HSSFCell.CELL_TYPE_BLANK) {
>
>                         nonBlankRowFound = true;
>
>                     }
>
>                 }
>
>                 if (nonBlankRowFound == true) {
>
>                     stop = true;
>
>                 } else {
>
>                     hsheet.removeRow(lastRow);
>
>                 }
>
>             }
>
>
>
>             sheets.add(hsheet);
>
>
>
> I hope it will be of some help to you guys.......
>
>
>
>
>
>
>
>
>
>
>
>
>
> Warm Regards,
>
> Mili Aggarwal
>
>
>
> --------------------------------------------------------------------------
--
> -----------------------------DISCLAIMER-----------------------------------
--
> --------------------------------------------------------------------------
--
> --------
>
>
>
> This message and any attachment contained here are information that is
> confidential, proprietary to HCL Technologies and its customers. Contents
> may be privileged or otherwise protected by law. The information is solely
> intended for the individual or the entity it is addressed to. If you are
not
> the intended recipient of this message, you are not authorized to read,
> forward, print, retain, copy or disseminate this message or any part of
it.
> If you have received this e-mail in error, please notify the sender
> immediately by return e-mail and delete it from your computer.
>
>
>
>
>
>
>
>
>
> -----Original Message-----
> From: Vyom Tewari [mailto:[EMAIL PROTECTED]
> Sent: Thursday, April 07, 2005 10:40 AM
> To: POI Users List
> Subject: Re: out of memory.
>
>
>
> hi Milli
>
>          can u send ur code ,in ur last mail u told that, u explicitly
>
> assign null to the workbook object inside loop ,it means gc should
>
> recollect it and according to u it is not working so if possible send ur
>
> code.
>
>
>
> ----- Original Message ----- 
>
> From: "Mili Aggarwal, Noida" <[EMAIL PROTECTED]>
>
> To: "POI Users List" <[email protected]>
>
> Sent: Thursday, April 07, 2005 9:58 AM
>
> Subject: out of memory.
>
>
>
>
>
> > He guys I have be unable to resolve out of memory error when I am
creating
>
> > 300 odd workbooks.
>
> > The structure of my app is:
>
> >
>
> > Reportgenerater is the class that calls 2 classes((Sheet1 and Sheet2))
by
>
> > passing them workbook object to Create sheets. The 2 classes create one
>
> > sheet each. There is a common class that consists of all STATIC styles
>
> that
>
> > are applied to both the sheets. Now the problem is - I am running out
>
> memory
>
> > since the workbooks objects are not being destroyed. Any ideas as to
what
>
> > can be done to destroy the objects?
>
> >
>
> >
>
> > Warm Regards,
>
> > Mili Aggarwal
>
> > HCL TECHNOLOGIES LTD.
>
> > Noida, India.
>
> > Tel: +91 (0120) 2516321/328 Extn: 1052
>
> > Email: [EMAIL PROTECTED]
>
> >
>
>
> --------------------------------------------------------------------------
>
> --
>
>
> -----------------------------DISCLAIMER-----------------------------------
>
> --
>
>
> --------------------------------------------------------------------------
>
> --
>
> > --------
>
> >
>
> > This message and any attachment contained here are information that is
>
> > confidential, proprietary to HCL Technologies and its customers.
Contents
>
> > may be privileged or otherwise protected by law. The information is
solely
>
> > intended for the individual or the entity it is addressed to. If you are
>
> not
>
> > the intended recipient of this message, you are not authorized to read,
>
> > forward, print, retain, copy or disseminate this message or any part of
>
> it.
>
> > If you have received this e-mail in error, please notify the sender
>
> > immediately by return e-mail and delete it from your computer.
>
> >
>
> >
>
> >
>
> >
>
> >
>
> >
>
> > Disclaimer:
>
> >
>
> > This message and any attachment(s) contained here are information that
is
>
> > confidential,proprietary to HCL Technologies and its customers,
privileged
>
> > or otherwise protected by law.The information is solely intended for the
>
> > individual or the entity it is addressed to. If you are not the intended
>
> > recipient of this message, you are not authorized to read, forward,
>
> > print,retain, copy or disseminate this message or any part of it. If you
>
> > have received this e-mail in error, please notify the sender immediately
>
> by
>
> > return e-mail and delete it from your computer.
>
> >
>
> >
>
> >
>
>
>
>
>
> ---------------------------------------------------------------------
>
> 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/
>
>
>
> Disclaimer:
>
> This message and any attachment(s) contained here are information that is
> confidential,proprietary to HCL Technologies and its customers, privileged
> or otherwise protected by law.The information is solely intended for the
> individual or the entity it is addressed to. If you are not the intended
> recipient of this message, you are not authorized to read, forward,
> print,retain, copy or disseminate this message or any part of it. If you
> have received this e-mail in error, please notify the sender immediately
by
> return e-mail and delete it from your computer.
>
>
>


---------------------------------------------------------------------
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/

Reply via email to