Re:The JVM Language Summit 2010
by johnswamps on Thursday July 29, 2010 @03:04PM
(#1558813)
Can someone explain the java/clojure code in the article? I'm assuming the jvm is able to make some sort of optimization because o was set to null which it wouldn't have been able to do otherwise?
[ Parent
| on HN ]
Re:The JVM Language Summit 2010
by frognibble on Thursday July 29, 2010 @03:59PM
(#1559026)
The goal of this trick is to reduce the memory required when the argument to the count function is a lazy sequence. When iterating through a lazy sequence, the items in the sequence are realized and retained by the sequence.
The code clears the stack slot for the count method argument. If the object referenced by the argument is not referenced elsewhere, then the object is eligible for gc during the execution of the count method. In the case where the argument is a lazy sequence, this changes the memory requirement from the entire realized sequence to a single item in the sequence.
This trick is employed everywhere in the Clojure implementation where a lazy sequence might be retained. It's not specific to the count function.