Re: [Chicken-users] Strange memory leak with lazy-seq
Hi Alex, On 24 February 2015 00:13 CET, Alex Shinn wrote: You may be falling short of the issue described by SRFI 45, which is that in all known Scheme implementations: (define (loop) (delay (force (loop (force (loop)) leaks memory. In R7RS this becomes (define (loop) (delay-force (loop))) which is required by the standard not to leak. I'm not sure why you don't observe a leak in the second example. Kooda and I discussed this issue on IRC yesterday and in fact, the first version doesn't leak when compiled either (he mixed up results when writing this email). So either the CHICKEN compiler is the first Scheme implementation to not leak memory in this case or something else is going on :-) Note that lazy-seq doesn't actually use delay / force internally but a custom implementation because up until http://code.call-cc.org/cgi-bin/gitweb.cgi?p=chicken-core.git;a=commit;h=9079b9b7ab57f296c9e3bf9f9cd42b1bad1a6baf CHICKEN promises would consume more and potentially leak memory as they didn't free the promise closure after realization. So as it stands, the leak only seems to occur in the interpreter. We also found that replacing `void' with `(lambda (_) (gc))' makes the leak go away when interpreted, too. Seems like there's some difference with how garbage collection is triggered compared to compiled code. Thanks for your input! Moritz ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Strange memory leak with lazy-seq
Hi John, On 24 February 2015 00:59 CET, John Cowan wrote: Lazy-map isn't lazy, so you are basically generating an eager list processing each element, and discarding the whole mess. that's not true, where did you get this idea? One way to try for yourself: (lazy-head (lazy-drop 10 (lazy-map sqrt (lazy-numbers = 3.16227766016838 Moritz ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Strange memory leak with lazy-seq
Moritz Heidkamp scripsit: Lazy-map isn't lazy, so you are basically generating an eager list processing each element, and discarding the whole mess. that's not true, where did you get this idea? A brain fart on my part. I was thinking of lazy (left) folds, which have to realize all the values (unless the kons function is itself a lazy constructor). -- John Cowan http://www.ccil.org/~cowanco...@ccil.org In computer science, we stand on each other's feet. --Brian K. Reid ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Strange memory leak with lazy-seq
On Tue, Feb 24, 2015 at 7:17 PM, Moritz Heidkamp mor...@twoticketsplease.de wrote: Hi Alex, On 24 February 2015 00:13 CET, Alex Shinn wrote: You may be falling short of the issue described by SRFI 45, which is that in all known Scheme implementations: (define (loop) (delay (force (loop (force (loop)) leaks memory. In R7RS this becomes (define (loop) (delay-force (loop))) which is required by the standard not to leak. I'm not sure why you don't observe a leak in the second example. Kooda and I discussed this issue on IRC yesterday and in fact, the first version doesn't leak when compiled either (he mixed up results when writing this email). So either the CHICKEN compiler is the first Scheme implementation to not leak memory in this case or something else is going on :-) Well, if lazy-seq doesn't actually use delay + force then it's not an exception :) I double checked, and for the code I wrote with delay + force, Chicken leaks both interpreted and compiled. -- Alex ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Strange memory leak with lazy-seq
Hi! I’ve been playing with lazy-seq for the past few days and found a very strange behaviour: The heap of the following program keeps growing rapidly in csi, running the same program after compilation seems to slow down the growth quite a lot but the heap isn’t constant as I was expecting it to be. Here is a test case of the problem: ; Start this script with `csi -:D -:hi100k -:hg101` to observe heap resizing (use lazy-seq) (define (complex-stream seq) (lazy-map identity seq)) ; This seems to leak: (lazy-each void (complex-stream (lazy-numbers))) ; This doesn't: #;(lazy-each void (lazy-map identity (lazy-numbers))) -- Envoyé depuis ma GameBoy. ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Strange memory leak with lazy-seq
Kooda scripsit: (define (complex-stream seq) (lazy-map identity seq)) Lazy-map isn't lazy, so you are basically generating an eager list processing each element, and discarding the whole mess. -- John Cowan http://www.ccil.org/~cowanco...@ccil.org Where the wombat has walked, it will inevitably walk again. (even through brick walls!) ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Strange memory leak with lazy-seq
On Mon, Feb 23, 2015 at 9:57 PM, Kooda ko...@upyum.com wrote: Hi! I’ve been playing with lazy-seq for the past few days and found a very strange behaviour: The heap of the following program keeps growing rapidly in csi, running the same program after compilation seems to slow down the growth quite a lot but the heap isn’t constant as I was expecting it to be. Here is a test case of the problem: ; Start this script with `csi -:D -:hi100k -:hg101` to observe heap resizing (use lazy-seq) (define (complex-stream seq) (lazy-map identity seq)) ; This seems to leak: (lazy-each void (complex-stream (lazy-numbers))) ; This doesn't: #;(lazy-each void (lazy-map identity (lazy-numbers))) You may be falling short of the issue described by SRFI 45, which is that in all known Scheme implementations: (define (loop) (delay (force (loop (force (loop)) leaks memory. In R7RS this becomes (define (loop) (delay-force (loop))) which is required by the standard not to leak. I'm not sure why you don't observe a leak in the second example. -- Alex ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users