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: How to determine control that fired event
    ... Imagine, say, 500 concurrent users and you will could potentially have 500 copies of the page's state stored in Session memory... ... My suggestion was to keep in memory a copy of an object that could contain datatables/datasets, various strings, longs, or other items as properties, and who knows what else as it would depend on the need of the application. ... That coupled with effective and efficient code to destroy objects no longer in use, garbage collection, and other methods, make using the Session area for storage and retrieval of items as I mentioned a highly valuable and accessible resource and tool to be exploited. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Bugcheck 101
    ... My chip has a hw dma queue and a hw render queue. ... The chip fetches command ... we're fetching from host memory. ... I hate to make such a silly suggestion but have you considered Googling ...
    (microsoft.public.development.device.drivers)
  • 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)