Understanding lazy-seq

61 views
Skip to first unread message

Edmund Jackson

unread,
Apr 12, 2010, 6:29:08 PM4/12/10
to clo...@googlegroups.com
Dear Clojurians,

I have been trying to get a proper grip on the operation of lazy-seq and hope somebody will have the time to clarify a point for me. The references indicate that you should not hold onto the head of a lazy sequence as it blocks the GC. This has lead to me to believe that a lazy sequence, even while being active 'downstream' can be GCd 'upstream'. Is this so ?

An example: in this post

http://groups.google.com/group/clojure/browse_thread/thread/57a12f1a0dab5e1b/cb3db6e6ac94092f?#cb3db6e6ac94092f

in the first version of fibo, the call (nth (fibo) 1000000) will cause a seq to proceed to the millionth element. If memory were tight could earlier elements be GC'd before nth had reached the end ? My understand is that it can. I ask because on my machine on Clojure 1.2, (nth (fibo) 1000000) causes a heap overflow which I don't understand.

Thanks in advance,

Edmund

Stuart Halloway

unread,
Apr 12, 2010, 7:53:51 PM4/12/10
to clo...@googlegroups.com
Hi Edmund,

This is a regression since last Tuesday's commit
f81e612cc9ff91ddefc1d86e270cd7f018701802. Thanks for catching it!

Stu

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient
> with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.

Sean Devlin

unread,
Apr 13, 2010, 8:33:20 AM4/13/10
to Clojure
How would one write a unit test to catch this type of thing?

On Apr 12, 7:53 pm, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> Hi Edmund,
>
> This is a regression since last Tuesday's commit  
> f81e612cc9ff91ddefc1d86e270cd7f018701802. Thanks for catching it!
>
> Stu
>
> > Dear Clojurians,
>
> >    I have been trying to get a proper grip on the operation of lazy-
> > seq and hope somebody will have the time to clarify a point for me.  
> > The references indicate that you should not hold onto the head of a  
> > lazy sequence as it blocks the GC.  This has lead to me to believe  
> > that a lazy sequence, even while being active 'downstream' can be  
> > GCd 'upstream'.  Is this so ?
>
> > An example:  in this post
>

> >http://groups.google.com/group/clojure/browse_thread/thread/57a12f1a0...

Rich Hickey

unread,
Apr 13, 2010, 9:32:13 AM4/13/10
to Clojure

On Apr 12, 7:53 pm, Stuart Halloway <stuart.hallo...@gmail.com> wrote:

> Hi Edmund,
>
> This is a regression since last Tuesday's commit  
> f81e612cc9ff91ddefc1d86e270cd7f018701802. Thanks for catching it!
>
> Stu
>
>
>
> > Dear Clojurians,
>
> >    I have been trying to get a proper grip on the operation of lazy-
> > seq and hope somebody will have the time to clarify a point for me.  
> > The references indicate that you should not hold onto the head of a  
> > lazy sequence as it blocks the GC.  This has lead to me to believe  
> > that a lazy sequence, even while being active 'downstream' can be  
> > GCd 'upstream'.  Is this so ?
>
> > An example:  in this post
>

> >http://groups.google.com/group/clojure/browse_thread/thread/57a12f1a0...


>
> > in the first version of fibo, the call (nth (fibo) 1000000) will  
> > cause a seq to proceed to the millionth element.  If memory were  
> > tight could earlier elements be GC'd before nth had reached the  
> > end ?  My understand is that it can.  I ask because on my machine on  
> > Clojure 1.2, (nth (fibo) 1000000) causes a heap overflow which I  
> > don't understand.
>
> > Thanks in advance,
>
> >  Edmund
>

Now fixed - thanks for the report!

Rich

Edmund Jackson

unread,
Apr 13, 2010, 11:04:02 AM4/13/10
to clo...@googlegroups.com
Wow - thanks everybody.

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.

Edmund

Reply all
Reply to author
Forward
0 new messages