Re: memory management



josh wrote:
in a while loop I get from a db some records and in the same time
I put them with an insert preparedStatement in
a destination db but the jave process increase the memory until it
goes in out of memory.

How can I optimize that? also If I increase Tomcat java memory when I
process more than 500 records
tha java memory is already at 700mb of usage!

GArlington wrote:
You can loop through the records (i.e. fetch them one-by-one), reuse
the same variables and run gc() after each (or few consecutive) loop
iterations.

It is bad advice to suggest using the gc() call.

It is also usually better to allocate new objects in the loop than to hang on to one for multiple iterations.

To the OP:

Provide an SSCCE.
<http://www.physci.org/codes/sscce.html>

You have a memory leak. It is in your code. The trick is to find from where.

Without an example that recreates the error we likely cannot help in detail. Candidates are objects that are not abandoned, contrary to GArlington's suggestion. You are probably not close()ing a ResultSet or a Connection, although that usually would cause problems before OutOfMemory (OOM).

GArlington's suggestion to process records one by one is sound. Are you storing many records' worth of information at once?

You probably need to refactor some logic into separate methods and classes.

The SSCCE will show us.

--
Lew
.



Relevant Pages

  • Re: BSOD minidumps... HELP!
    ... You can rely on the Windows Firewall and do not have to ... Background information on Stop Error message 0x50http://msdn2.microsoft.com/en-us/library/ms793437.aspx ... Requested data was not in memory. ... Any suggestion for an alternate firewall that has ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: BSOD minidumps... HELP!
    ... You can rely on the Windows Firewall and do not have ... Requested data was not in memory. ... RAM) or incompatible software (including remote control and antivirus ... Any suggestion for an alternate firewall that has ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Office 2001: Cant save in Excel or Word
    ... OK - My next suggestion is to trash "Carbon Registration database" and see ... Make sure you have have plenty of real RAM for your computer. ... > vitual memory off in the memory control panel. ... > Then I opened on of the excel files I had brought over from the PC and ...
    (microsoft.public.mac.office.excel)
  • Re: Installing Memory Problem
    ... Andrew E. posted a suggestion that sounds promising. ... >> I'm having problems installing Ram in a computer I'm building. ... They are the correct memory sticks for the MB. ... >> must install one of your two memory modules on DDR3. ...
    (microsoft.public.windowsxp.hardware)
  • Re: memory counters gone
    ... suggestion be i tried it already ... still doesn't show many counters like 'memory' in the list of counters. ... > I set 'no page file', booted into safe mode, ran performance monitor, set PF ...
    (microsoft.public.windowsxp.general)