Re: Get "java.lang.OutOfMemoryError" when Parsing an XML useing DOM
NeoGeoSNK wrote:
....
I don't know how DOM works when it parsing a XML, I use DOM that is
because the XPath can quciky location some particular elements. I
think if the SAX only reports events but not store the whole structure
of XML like DOM does, It must be more efficient. What does "page-
thrashing" means ?
....
Imagine working in an office, doing some complicated task, using a desk
with a limited area, and a file cabinet with far more paper in it than
can fit on the desk.
The desk top is usually full, so when you need to create a new document
or get something from the filing cabinet, you need to remove something
from the desk. The easiest way is to just get rid of a paper you have
not looked at recently.
There are two very different cases:
1. The pages you need more often than once every few minutes all fit on
the desk. You spend most of your time working, but sometimes have to get
another paper from the file cabinet.
2. The task you are doing needs far more papers than can fit on the
desk. Every time you need to follow up a reference, it points to a page
that is in the filing cabinet, and you cannot make progress until you
get it. But to put it on the desk, you have to remove something else,
and a few minutes later you need the page that you just removed...
The second condition is page thrashing.
desk top <-> computer's main memory
file cabinet <-> swap file
page of paper <-> virtual storage page
There are two cases when building the whole document in memory:
1. It fits. In that case there will be a heap size that is both big
enough to hold the document (no out of memory errors) and small enough
to fit on the desk (no page thrashing, the computer spends most of its
time doing useful work, not shuffling pages between disk and memory).
The obvious heap size to try is a bit smaller than the computer's
physical memory. If any size works, that one will.
2. It does not fit. Any memory size big enough to avoid OutOfMemoryError
is big enough to cause page thrashing.
Patricia