This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Retrieving resources from Scheme
- From: Andy Dwelly <andy dot dwelly at safedataco dot com>
- To: kawa at sourceware dot org
- Date: Wed, 05 Jul 2006 11:29:23 +0100
- Subject: Retrieving resources from Scheme
I'm experimenting with Kawa under JDK 1.5.0_4 and I have a program that
repeatedly creates
new Scheme objects, evaluates a series of functions and then discards them.
This is not particularly efficient but there are circumstances where doing
this makes sense. My own case is a bit of research into searching the
space of randomly
generated programs (Chaitan space ?) and I can imagine doing something
similar
with web applications as well.
I've run into what looks like a memory leak problem. I can make this
happen most easily
with the following class:
import gnu.mapping.Environment;
import kawa.standard.Scheme;
public class SchemeLeakTest {
//Member
Variables////////////////////////////////////////////////////////////
//Constructors////////////////////////////////////////////////////////////////
public SchemeLeakTest() {
Scheme.registerEnvironment();
int count = 0;
while (true) {
try {
count++;
if (count % 100 == 0) {
System.out.print(".");
if (count % 1000 == 0) {
System.out.println();
}
}
Scheme scm = new Scheme();
Environment env = scm.getEnvironment();
scm.eval("(load \"prequel.scm\")", env);
scm.eval("(iflte 0 10 (expt 2.7 10.3) (expt 7.1 9.8))", env);
scm.eval("(iflte 10 0 (expt 2.7 10.3) (expt 7.1 9.8))", env);
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}
//Public
Methods//////////////////////////////////////////////////////////////
public static void main(String[] args) {
SchemeLeakTest test = new SchemeLeakTest();
}
//Private
Methods/////////////////////////////////////////////////////////////
}
where the prequel.scm file is defined as:
(define (% a b)
(if (= b 0) 0
(/ a b)))
(define-syntax iflte
(syntax-rules ()
((iflte a b c d) (if (<= a b) c d))))
.....my first thought that this was someing to do with the load command
or the
invocation of macros. In fact eliminating load does fix this particular
problem in this single case. However
I have a much larger more complex example that neither loads nor uses
macros. I can
invoke around 3000 Scheme objects before it runs out of heapspace. My
netbeans profiler
suggests that the larger example ReferenceExp, and CPoolUTF8 classes
from Gnu are somehow
involved since theyseem to accumulate more or less endlessly.
Is there anything known on this subject apart from the discussion in
2003 on servlets ? I'd be happy to forward my larger example
if it helps...
Andy