Re: memory management
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 09:14:12 -0400
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
.
- Follow-Ups:
- Re: memory management
- From: Roedy Green
- Re: memory management
- References:
- memory management
- From: josh
- Re: memory management
- From: GArlington
- memory management
- Prev by Date: Re: What's wrong with this sentence?
- Next by Date: Re: memory management
- Previous by thread: Re: memory management
- Next by thread: Re: memory management
- Index(es):
Relevant Pages
|
|