[plt-scheme] Lazy streams and memory in sxml's lazy:xml->sxml / lazy:sxpath?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Mon May 8 06:21:40 EDT 2006

Hi everyone,

I've been writing some test code with sxml's lazy parser for the 
Schematics Cookbook:

     http://schemecookbook.org/view/Cookbook/ParsingWithLazySxml

and although my examples initially appears to work, I can see that memory 
usage just continues to go up as the file is parsed by watching 'top'. 
This goes against what I expected --- I really expected to see constant 
memory usage.

I do know that simple stream usage should work without incurring a memory 
leak.  I know that:

;;;;;;
(module test-streams-good mzscheme
   (require (lib "list.ss"))

   (define (make-lazy-list-of-ones)
     (cons 1
           (delay (make-lazy-list-of-ones))))

   (let loop ([lst (make-lazy-list-of-ones)])
     (loop (force (rest lst)))))
;;;;;;


is perfectly fine in using a bounded amount of memory.


I suspect, though, that I'm seeing behavior analogous to what happens when 
we hold onto the head of a stream:

;;;;;;
(module test-streams-bad mzscheme
   (require (lib "list.ss"))

   (define (make-lazy-list-of-ones)
     (cons 1
           (delay (make-lazy-list-of-ones))))

   (define my-list-of-ones (make-lazy-list-of-ones))

   (let loop ([lst my-list-of-ones])
     (loop (force (rest lst)))))
;;;;;;

My hope is that what I'm seeing is a bug in SXML, or else I'm really not 
understanding my code.  *grin*

It's late now, but tomorrow I'll start looking into SXML's use of lazy 
streams to see if I can spot something weird.  But I just wanted to check 
with others here to make sure I'm not missing something obviously silly.


Thanks for any help on this!


Posted on the users mailing list.