[英]How can I leak memory in Clojure?
For a presentation at the Bay Area Clojure Meetup on Thursday I am compiling a list of ways to leak memory in Clojure. 周四在Bay Area Clojure Meetup上的一个演示文稿中,我正在编写一个在Clojure中泄漏内存的方法列表。
So far I have: 到目前为止,我有:
What else? 还有什么?
By keeping a reference to a seq on a large collection. 通过在大型集合上保留对seq的引用。 eg:
例如:
(drop 999990 (vec (range 1000000)))
returns a seq of ten elements that holds a reference to the whole vector! 返回一个包含十个元素的seq,它们包含对整个向量的引用!
There is the intern call as well. 还有实习生电话。
Note that your examples are not leaking memory in the common sense of the word. 请注意,您的示例不会在常识中泄漏内存。 You can still access the objects (not sure about the classes -- I assume one can re-find them via some API), ie they haven't been lost.
您仍然可以访问对象(不确定类 - 我假设可以通过某些API重新找到它们),即它们没有丢失。 With certain things like the classes and interned strings it is just impossible to forget the data so the effect is the same.
对于像类和实习字符串这样的某些东西,忘记数据是不可能的,所以效果是一样的。
Clojure memory leaks will usually be very similar to Java memory leaks. Clojure内存泄漏通常与Java内存泄漏非常相似。 However the fact that collections are "persistent" means that if you add something into a collection and don't realize that you retained a reference to the old version of the collection as well as the new value means that memory is consumed to keep the old version hanging around.
但是,集合是“持久的”这一事实意味着,如果您将某些内容添加到集合中并且没有意识到您保留了对旧版本集合的引用以及新值意味着使用内存来保留旧内容版本闲逛。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.