Hi,

On Wed, Jan 13, 2010 at 1:30 AM, Manish <manish.zed...@gmail.com> wrote:
> Thanx for ur response,
> Actually We are using string builder in our project, String Builder
> causing the memory leak in as I google, Thats the main reason i want
> to set the StringBuilder object to nil,
> We are using the htmlunit core js library for fetching the web pages
> which require the javascript enabled. The Decompiler.java using a
> variable StringBuilder result = new  StringBuilder(); Netbeans
> profiler showing that this is the object consuming maximum of memory
> causing memory leak. Thats the reason only I want to set the
> StringBuilder object in our project to null. I also found on net that
> strbuilder.toString() also causing the memory leak. So in place of
> toString() we are trying to use substring(0). Like:
>
> (defn #^String element-text
>  ([thing]
>     (let [delimiter #s""]
>       (element-text thing delimiter)
>       ))
>  ([thing #^String delimiter]
>     (if (instance? Node thing)
>       (node-text thing)
>       (let [buf (StringBuilder.)]
>         (doseq [#^Node e thing]
>           (node-text e buf delimiter))
>         (let [res (.substring buf 0)]
>           (.setLength buf 0)
>           res)))))

Substrings do indeed share memory with their parent strings, and this
will prevent the parents from being garbage-collected.

Try changing this:

  (let [res (.substring buf 0)]
          (.setLength buf 0)
          res))

to:

    (String. buf)

and see if your memory problem goes away. Allocating a new String
should copy the StringBuilder buffer, not sharing any storage with it,
and letting the StringBuffer storage be reclaimed.

Best,
Graham
-- 
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

Reply via email to