newbie encountering java.lang.OutOfMemoryError: Java heap space
Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are in https://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
(Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are in https://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... - http://esperanto.net - http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are in https://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... - http://esperanto.net - http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
Aviad, Welcome to Clojure. I don't want to tell you how to solve it. That's all part of the fun. But my hint to you would be that you don't need to keep all 1 million lists in memory. In fact, you should be able to solve this problem by only keeping three numbers in memory at any one time: The number that has produced the longest chain, the size of the longest chain and the size of the current chain you are working on. Also, as I was recently reminded by this group, it is never a good idea to use def within a function. This problem can be solved using only pure functions. Good luck, Brenton On Feb 10, 7:13 am, Aviad Reich avi@gmail.com wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are inhttps://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... -http://esperanto.net -http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
Hi Aviad, Disclaimer: I haven't read the book, nor do I know Clojure very well. However, based on your question (which I did read) and Brenton's hint, it seems to me like the solution will involve a lazy sequence, which is a frequent tool to use whenever you're dealing with a problems that involve a lot of memory. - Greg On Feb 10, 2010, at 10:13 AM, Aviad Reich wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are in https://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... - http://esperanto.net - http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
Thank you all! your advice were indeed very helpful! I eventually solved it using memoization. and indeed keeping only (http://clojure-euler.wikispaces.com/Problem+014 - lxmonk if you're interested) This indeed is a great community, so let me try another (related) question. Comparing my solution with an identical one - but without memoization produces a faster result. I understand that caching all the results has some overhead, but how come it isn't balanced with the speedup from the cached values? Again, Thanks! Aviad On 10 February 2010 19:40, Greg g...@kinostudios.com wrote: Hi Aviad, Disclaimer: I haven't read the book, nor do I know Clojure very well. However, based on your question (which I did read) and Brenton's hint, it seems to me like the solution will involve a lazy sequence, which is a frequent tool to use whenever you're dealing with a problems that involve a lot of memory. - Greg On Feb 10, 2010, at 10:13 AM, Aviad Reich wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are in https://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... - http://esperanto.net - http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
אביעד On 10 February 2010 19:54, Aviad Reich avi@gmail.com wrote: Thank you all! your advice were indeed very helpful! I eventually solved it using memoization. and indeed keeping only 3 values in memory. (http://clojure-euler.wikispaces.com/Problem+014 - lxmonk, if you're interested) This indeed is a great community, so let me try another (related) question. Comparing my solution with an identical one - but without memoization produces a faster result. I understand that caching all the results has some overhead, but how come it isn't balanced with the speedup from the cached values? Again, Thanks! Aviad On 10 February 2010 19:40, Greg g...@kinostudios.com wrote: Hi Aviad, Disclaimer: I haven't read the book, nor do I know Clojure very well. However, based on your question (which I did read) and Brenton's hint, it seems to me like the solution will involve a lazy sequence, which is a frequent tool to use whenever you're dealing with a problems that involve a lot of memory. - Greg On Feb 10, 2010, at 10:13 AM, Aviad Reich wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are in https://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... - http://esperanto.net - http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
Aviad, You don't get a speedup because you are never calling the memoized function with the same arguments. In your code, n is different each time. memoize basically creates a map of arguments to results. When you call the function with args that it has seen before it bypasses actually calling the underlying function and just returns the results. If you really wanted to use memoize here then you use it on the vl function. Brenton On Feb 10, 9:54 am, Aviad Reich avi@gmail.com wrote: Thank you all! your advice were indeed very helpful! I eventually solved it using memoization. and indeed keeping only (http://clojure-euler.wikispaces.com/Problem+014- lxmonk if you're interested) This indeed is a great community, so let me try another (related) question. Comparing my solution with an identical one - but without memoization produces a faster result. I understand that caching all the results has some overhead, but how come it isn't balanced with the speedup from the cached values? Again, Thanks! Aviad On 10 February 2010 19:40, Greg g...@kinostudios.com wrote: Hi Aviad, Disclaimer: I haven't read the book, nor do I know Clojure very well. However, based on your question (which I did read) and Brenton's hint, it seems to me like the solution will involve a lazy sequence, which is a frequent tool to use whenever you're dealing with a problems that involve a lot of memory. - Greg On Feb 10, 2010, at 10:13 AM, Aviad Reich wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are inhttps://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... -http://esperanto.net -http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group,
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
Looking at your post I notice some things that strike me as 'odd'. The use of (def) in a form that is not a top most form. From my experience this leads to trouble in the best of times. I think a better way would be to close over your known-map with a closure. While I don't have high hopes that closing over known-map will solve your out of memory issue it starts, i believe, making the code more idiomatic. Once that is done I would look at simplifying what update- known-map and dist functions do. Its unclear to me why you do a merge of a zipmap of keys to numbers. Making that clearer might help. I also don't understand your use of a map to hold the intermediate solutions. My first thought upon reading the question was a pair of numbers, the first being the number and the second being the count of the Collatz chain would do the trick, but I could be missing something. (William Hidden) On Feb 10, 10:13 am, Aviad Reich avi@gmail.com wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are inhttps://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... -http://esperanto.net -http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie encountering java.lang.OutOfMemoryError: Java heap space
Again, your input was incredibly beneficial for me. William: Thank you for your comments. As i wrote, eventually I came up with a different solution altogether. To answer your question concerning the previous code: my initial idea was that since (although unproven) all the different sequences finally converge to the 2^n series, and other sequences in different points (e.g the sequence starting with 5 converges with the one starting at 16), it would be possible to speed up the computation if i would have created a map where past sequences are kept. The idea was that the keys to the map are numbers already calculated and their respective values would be their chain-lengths. That is the reason I wanted to merge the known-map with a (zip)map whose keys are the unknown numbers in the current sequence (kept in the cur-map vector) and values - chain lengths - are those of the number who converged with an already known sequence plus one. This method proved to be consuming too much memory, hence my use a slightly different approach. You have all been very helpful! Cheers, Aviad On 10 February 2010 19:32, Will Hidden william.hid...@gmail.com wrote: Looking at your post I notice some things that strike me as 'odd'. The use of (def) in a form that is not a top most form. From my experience this leads to trouble in the best of times. I think a better way would be to close over your known-map with a closure. While I don't have high hopes that closing over known-map will solve your out of memory issue it starts, i believe, making the code more idiomatic. Once that is done I would look at simplifying what update- known-map and dist functions do. Its unclear to me why you do a merge of a zipmap of keys to numbers. Making that clearer might help. I also don't understand your use of a map to hold the intermediate solutions. My first thought upon reading the question was a pair of numbers, the first being the number and the second being the count of the Collatz chain would do the trick, but I could be missing something. (William Hidden) On Feb 10, 10:13 am, Aviad Reich avi@gmail.com wrote: thank you. I have -server and -Xmx1024m set in my 'swank-clojure-extra-vm-args, but the problem remains. Aviad On 10 February 2010 15:57, Joop Kiefte iko...@gmail.com wrote: (Disclaimer: never tried myself) http://hausheer.osola.com/docs/5 2010/2/10 Aviad R avi@gmail.com Hi all. I'm trying to learn clojure with the excellent Programming Clojure and projecteuler.net. I am encountering the java heap space error, and can't find a workaround, nor a smarter way to write my code (which I am certain exist). Trying to solve Problem 14 (some spoilers might be ahead, for those wanting to solve it in the future). The problem and my code are inhttps://pastee.org/hj3sh here is the problem: I am trying to produce a map of one O(million) key-value pairs using a recursive function. I can produce a map of the first 10 numbers in ~1300 msecs, with 217211 keys. However, for 15 and up, I get java.lang.OutOfMemoryError: Java heap space. so, I assume my code is ok on efficiency, but the recursion is too deep. am I right? can anyone suggest a way to overcome this problem? any additional tips and thoughts on the code would be of great help to me, as I am making my first steps in clojure. Thank you, Aviad -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com clojure%2bunsubscr...@googlegroups.comclojure%252bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Communication is essential. So we need decent tools when communication is lacking, when language capability is hard to acquire... -http://esperanto.net -http://esperanto-jongeren.nl Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@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+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com clojure%2bunsubscr...@googlegroups.comclojure%252bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send