i have this test code (note the commented version w/o with-cwd):
$ cat leaks.scm
#!/usr/bin/scsh \
-e test-files -s
!#
;; read filenames (1 per line) on stdin
(define (test-files args)
(awk (read-line) (line) ()
(#t
;(if (file-directory? line)
(let ((dir line))
;(directory-files dir #f) ; this version works ok
(with-cwd dir ; this version doesn't free memory
(directory-files "." #f)
)))))
Now, let's prepare a big fs tree (under ./test):
$ time (for i in 1 2 3 4 5 6 7 8 9;\
do for j in 1 2 3 4 5 6 7 8 9; \
do for k in 1 2 3 4 5 6 7 8 9; \
do for l in 1 2 3 4 5 6 7 8 9; \
do mkdir -p test/$i/$j/$k/$l; \
done;done;done; done; )
4,54s user 13,10s system 58% cpu 30,283 total
now to see the problem:
$ find ./test -type d | ./leaks.scm
and watch the memory consumption (i do w/ mempeak).
w/ scsh 0.6.4 i see it growing to ~ 46 MB (on bigger tree it keeps growing)
If i try the version (directory-files dir #f) it stabilizes at ~21MB.
|