Everything tbc++ said, But also, if you create futures at a faster rate then they terminate, you will eventually run out of memory, because futures are unbounded. If that's the case, you want to use ThreadPoolExecutor to create a bounded pool or a pool backed by a queue and then use it as explained here: https://purelyfunctional.tv/guide/clojure-concurrency-the-ultimate-guide/
On Tuesday, 5 September 2017 14:00:04 UTC-7, tbc++ wrote: > > Every thread created on the JVM takes about 2MB of memory. Multiply that > by that number of threads, and I'm surprised your memory usage is that low. > But the futures thread pool will also re-use previously created threads for > new futures. In order to optimize this, a certain number of threads will be > kept around for some time incase they need to be reused. In my limited > testing it takes about a minute for the pool to decide to shutdown the > threads. > > On top of all that, you're measuring the JVM memory usage through Window's > task manager, from what I can tell. Internally the JVM may be using way > less memory, but it hasn't bothered to give that back to the OS yet because > it guesses that if you used this much memory in the past, you may use that > amount again soon. In certain configurations, the JVM may never give the > memory back the OS. So if you want accurate memory usage stats you should > use a tool that can look into the internals of the JVM, or perhaps use some > of the GC stats you can access via the Runtime class. > > On Tue, Sep 5, 2017 at 2:14 PM, Max Muranov <pho...@gmail.com > <javascript:>> wrote: > >> Hello! I've read in this >> <https://groups.google.com/forum/#!topic/clojure/CRStVPHjg8o> thread >> that futures are garbage collected and it's okay to use them for side >> effects. But what about such program? >> >> (dotimes [n 100000] >> (future (Thread/sleep 1000))) >> >> After performing the code several times I see this in my task manager: >> >> >> After each performing the amount of using memory increases. So how can I >> use futures to free the memory after they were finished? >> >> -- >> 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 >> <javascript:> >> 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 <javascript:> >> 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 unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > “One of the main causes of the fall of the Roman Empire was that–lacking > zero–they had no way to indicate successful termination of their C > programs.” > (Robert Firth) > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.