This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
RE: Kawa servlet leaks
- From: "Dominique Boucher" <dboucher at nuecho dot com>
- To: "'Kawa List'" <kawa at sources dot redhat dot com>
- Date: Wed, 19 Nov 2003 11:11:19 -0500
- Subject: RE: Kawa servlet leaks
Hi,
Here is an update. I wrote a very dumb servlet in Java that calls a
Scheme function. The latter writes a profile in XML to the response
output stream. I wrote two versions of the Scheme function. One that
creates an output port and uses format, the other directly writes to the
output stream. In the former case, there is a leak. In the latter, no
leak.
Dominique
Here are the three files:
------------------------- getprofile.java
import java.io.OutputStream;
import javax.servlet.http.*;
public class getprofile extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
{
OutputStream os = response.getOutputStream();
formatprofile.formatProfile(os);
}
}
------------------------- formatprofile-with-leak.scm
(module-name <formatprofile>)
(module-static #t)
(define (format-profile (os :: <java.io.OutputStream>)) :: <void>
(let ((port (make <gnu.mapping.OutPort> os)))
(format port "<?xml version=\"1.0\" encoding=\"UTF-8\"?>~%")
(format port "<profile>~%")
(format port " <id>12345</id>~%")
(format port " <langue>fr</langue>~%")
(format port " <nom>Dominique</nom>~%")
(format port " <sexe>M</sexe>~%")
(format port "</profile>~%")
(invoke os 'flush)
(invoke os 'close)))
------------------------- formatprofile.scm
(module-name <formatprofile>)
(module-static #t)
(define (format-profile (os :: <java.io.OutputStream>)) :: <void>
(invoke os 'write (invoke (as <String> "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n") 'getBytes))
(invoke os 'write (invoke (as <String> "<profile>\n") 'getBytes))
(invoke os 'write (invoke (as <String> " <id>12345</id>\n")
'getBytes))
(invoke os 'write (invoke (as <String> " <langue>fr</langue>\n")
'getBytes))
(invoke os 'write (invoke (as <String> " <nom>Dominique</nom>\n")
'getBytes))
(invoke os 'write (invoke (as <String> " <sexe>M</sexe>\n")
'getBytes))
(invoke os 'write (invoke (as <String> "</profile>\n") 'getBytes))
(invoke os 'flush)
(invoke os 'close))