One piece of background info: a Java String is surprisingly
large. There's a 16-byte overhead of each Java object, and a String is
actually two objects (the String and the array it contains) for a
total of 32 bytes of heap overhead. Then there's the 12 bytes for
String's members, and the 4 bytes for the array's length. Then there
are the characters at two bytes per character. So a 10-character
String is 32 + 12 + 4 + 20 = 68 bytes.
You've taken your objects, which probably share a lot of String
constants in their properties, and you've created Strings of Jess
code. Jess parses those Strings to create Fact objects. When a Fact
has a slot that contains a String, Jess is parsing that little String
out of your big one. It is creating a new String object for each slot
value in each Fact, because it has no other choice. So whereas a lot
of your Java objects may share String constants, your Jess facts all
contain unique ones. Even if the Java objects don't share constants,
your Jess facts still contain copies, so there's twice as much String
data as before.
So this is a long way of saying that if you create your 67000 Fact
objects using Jess's Java API and assert them using assertFact(), they
will use much less memory. If they STILL don't fit, then that's what
the -Xmx switch is for.
I think Matthew Hutchinson wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> G'day all,
>
> I'm happy to say my code is working fine, but my question is about Jess,
> Java and memory. I plan to use shadow facts in conjunction with a DB in
> order to store large numbers of facts - but only get 'em when I need 'em.
> Anyway, in the mean time, I was just going to assert a whole bunch of facts
> (say, 66927) into Jess so I could work with them directly - and do the
> database stuff later. But when trying to do this, I get the following error:
>
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
>
> I know my code works fine, as I tested it with only asserting 200 facts. Is
> this just simply because Jess ran out memory? A great reason why to use the
> database/shadow fact technique mentioned previously?
>
> My code, if it's relevant:
> -----------------------------------------
>
> public void writeJessFacts(String jf)
> {
> String factsFilename = jf;
>
> try
> {
> engine.executeCommand("(deftemplate street_name_alias \"fact
> template\" (slot actual_name) (slot actual_type) (slot dli_id) (slot
> soundex) (multislot alias) (slot lga) (slot locality) )");
> int count = 0;
> for (count = 0; count < street_name_array.size(); count++)
> //for (count = 0; count < 200; count++)
> {
> engine.executeCommand("(assert (street_name_alias
> (actual_name \""+street_name_array.get(count).toString()+"\") " +
>
> "(actual_type \""+street_type_array.get(count).toString()+"\") " +
> "(dli_id
> "+street_name_ID_array.get(count).toString()+" ) " +
> "(lga
> \""+lga_name_array.get(count).toString()+"\") " +
> "(locality
> \""+locality_name_array.get(count).toString()+"\") " +
> "(soundex
> \""+soundex_code.get(count).toString()+"\") ) )");
> }
> System.out.println("A total of " + count + " facts asserted");
> engine.executeCommand("(save-facts "+factsFilename+"
> street_name_alias)");
> System.out.println(count + " facts written to file (Jess
> format)");
> }
>
> catch (JessException e)
> {
> System.out.println("error with knowledge base: " + e);
> }
> }
>
> -----------------------------------------
>
> A sample fact as written to file:
>
> (MAIN::street_name_alias (actual_name "ANNA PLAINS") (actual_type "RD")
> (dli_id 100060001) (soundex "A514") (alias ) (lga "BROOME") (locality
> "EIGHTY MILE BEACH"))
>
>
>
> Thanks all,
> Matt
>
>
>
>
> --
> Matthew Hutchinson
> Ph.D. Candidate
> Department of Spatial Sciences
> Curtin University of Technology
> GPO Box U1987
> Perth, Western Australia 6845
>
> Visiting Scholar
> Department of Geography and Planning
> University of Akron
> Akron, Ohio USA
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------