[Pellet-users] Pellet-backed models not being garbage collected
Alan Ruttenberg
alanruttenberg at gmail.com
Tue Jun 24 05:54:36 UTC 2008
Any reason not to implement a finalize method so that the model gets
closed if it is no longer referenced?
-Alan
On Jun 23, 2008, at 11:26 PM, Evren Sirin wrote:
> Garbage collection will happen only if you call model.close()
> explicitly. Otherwise some references to internal fields stay around
> preventing gc and ultimately causing OutOfMemory. In your example
> program calling model.close() at the end of each iteration solved the
> problem on my side.
>
> Cheers,
> Evren
>
> PS: There were some issues we identified regarding model.close()
> operation in Pellet (and will be fixed in the next version). That bug
> prevented gc even if you explicitly close the model. But that occurs
> when the same Pellet model was reused. This is not the case here so
> that
> bug should not affect you.
>
> On 6/23/08 1:16 PM, Todor Dimitrov wrote:
>> Hi everyone,
>>
>> I'm trying to use pellet in a "production" system where different
>> ontologies have to be loaded upon request. The system is comprised of
>> a knowledge base with only ONE loaded pellet-backed model at a time.
>> I've assumed that whenever I create a new model the old one should be
>> garbage collected. This is obviously not the case as I keep getting
>> "OutOfMemory" errors. Here is a sample piece of code to test the
>> behavior:
>>
>> /**
>> * *@author* Todor Dimitrov (todor.dimitrov at stud.uni-due.de
>> <mailto:dimitrov at stud.uni-due.de>)
>> * *@version* Jun 23, 2008 3:26:02 PM
>> */
>> *public* *class* TestJenaPellet {
>>
>> /** The base URI for the domain model */
>> *public* *static* *final* String /MODEL_URI/ = "http://www.owl-
>> ontologies.com/domain-ontology.owl#";
>>
>> /** The base URI for the instances model */
>> *public* *static* *final* String /INSTANCES_URI/ = "http://www.owl-
>> ontologies.com/test-ontology.owl#";
>>
>> /** Prefix for all SPAQL queries */
>> *public* *static* *final* String /SPARQL_PREFIX/ = "PREFIX domain:
>> <" + /MODEL_URI/
>> + ">\n"
>> + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
>> + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
>> + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n";
>>
>> *static* {
>> *final* OntDocumentManager manager = OntDocumentManager./
>> getInstance/();
>> *final* String modelUri = /MODEL_URI/.substring(0, /MODEL_URI/
>> .lastIndexOf("#"));
>> *try* {
>> manager.addAltEntry(modelUri, TestJenaPellet.*class*.getResource(
>> "domain-ontology.owl").toString());
>> } *catch* (Exception ex) {
>> *throw* *new* RuntimeException(ex);
>> }
>> }
>>
>> /**
>> * Retrieves the pellet model
>> *
>> * *@return* the non-null model
>> */
>> *private* *static* OntModel getPelletModel() {
>> *final* OntModel baseModel = /getBaseModel/();
>> *return* ModelFactory./createOntologyModel/(PelletReasonerFactory./
>> THE_SPEC/,
>> baseModel);
>> }
>>
>> /**
>> * Retrieves the base model
>> *
>> * *@return* the non-null base model
>> */
>> *private* *static* OntModel getBaseModel() {
>> *final* OntModel ontModel = ModelFactory
>> ./createOntologyModel/(OntModelSpec./OWL_DL_MEM/);
>> *final* String modelUri = /MODEL_URI/.substring(0, /MODEL_URI/
>> .lastIndexOf("#"));
>> *final* String instanceUri = /INSTANCES_URI/.substring(0, /
>> INSTANCES_URI/
>> .lastIndexOf("#"));
>> *final* Ontology ontology = ontModel.createOntology(instanceUri);
>> ontology.addImport(ontModel.createResource(modelUri));
>> ontModel.loadImports();
>> *return* ontModel;
>> }
>>
>> /**
>> * Executes SPARQL queries
>> */
>> @Test
>> *public* *void* testQueries() *throws* Exception {
>> *final* String queryString = "select ?room where {?room rdf:type
>> domain:Room.}";
>> *final* Set<Individual> rooms = *new* HashSet<Individual>();
>> *for* (*int* i = 0; i < 10000; i++) {
>> rooms.clear();
>> *final* OntModel model = /getPelletModel/();
>> // final OntModel model = getBaseModel();
>> *final* QueryExecution qe = QueryExecutionFactory./create/(
>> /SPARQL_PREFIX/ + queryString, model);
>> *try* {
>> // Execute the query and obtain results
>> *final* ResultSet result = qe.execSelect();
>> *while* (result.hasNext()) {
>> *final* QuerySolution solution = result.nextSolution();
>> *final* RDFNode node = solution.get("room");
>> *final* Individual room = model.getIndividual(node.asNode()
>> .getURI());
>> rooms.add(room);
>> }
>> } *finally* {
>> // Important - free up resources used running the query
>> qe.close();
>> }
>> System./out/.println("Iteration " + (i + 1) + " :: number of rooms: "
>> + rooms.size());
>> }
>> }
>> }
>>
>> and the very simple ontology:
>>
>> <?xml version="1.0"?>
>> <rdf:RDF
>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>> xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
>> xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
>> xmlns:owl="http://www.w3.org/2002/07/owl#"
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>> xmlns:swrl="http://www.w3.org/2003/11/swrl#"
>> xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
>> xmlns="http://www.owl-ontologies.com/domain-ontology.owl#"
>> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>> xml:base="http://www.owl-ontologies.com/domain-ontology.owl">
>> <owl:Ontology rdf:about=""/>
>> <owl:Class rdf:ID="Room"/>
>> <Room rdf:ID="Room_4"/>
>> <Room rdf:ID="Room_3"/>
>> <Room rdf:ID="Room_5"/>
>> <Room rdf:ID="Room_6"/>
>> <Room rdf:ID="Room_1"/>
>> <Room rdf:ID="Room_10"/>
>> <Room rdf:ID="Room_9"/>
>> <Room rdf:ID="Room_11"/>
>> <Room rdf:ID="Room_7"/>
>> <Room rdf:ID="Room_2"/>
>> <Room rdf:ID="Room_12"/>
>> <Room rdf:ID="Room_8"/>
>> </rdf:RDF>
>>
>> In the "testQueries()" method approximately 700-800 iterations are
>> possible (with the default heap size!). If I only use the base model,
>> the program terminates normally. Does pellet cache any of the models
>> and is there a way to clear the cache?
>>
>>
>> Thanks in advance,
>>
>> Todor
>> ---------------------------------------------------------------------
>> ---
>>
>> _______________________________________________
>> Pellet-users mailing list
>> Pellet-users at lists.owldl.com
>> http://lists.owldl.com/mailman/listinfo/pellet-users
>> _______________________________________________
>>
>> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
>
> _______________________________________________
> Pellet-users mailing list
> Pellet-users at lists.owldl.com
> http://lists.owldl.com/mailman/listinfo/pellet-users
> _______________________________________________
>
> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
More information about the Pellet-users
mailing list