I want to make it clear, that it probably isn't Clojure's memory
problem but something with my code.

Anyway, I was trying to figure out my heap memory goes up so much on
various operations in my application.  Sure, it could be anything but
I know I am doing something wrong.

Here is the application, a text editor in SWT.  When I open files, the
heap memory goes up 10 times the size of the file.  So, if I open a
3MB file, that is 30MB of heap memory used.

http://code.google.com/p/lighttexteditor/
------------------------

There are also some bad designs I am using, still wouldn't explain a
10 fold increase in memory.

http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojure/light/toolkit/

So far, I have done a couple of things.

1. Turned on warn on reflection and reduced some of the reflection
calls by adding type hints.

2. Tried to reduce the number of calls to deref and not use "global?"
defines.

Here is the code that I think is the worst offender.  Basically, a
java oriented approach for opening a file.

(defn open-file-util [file file-path]
  #^{:doc "Use java oriented approach for loading a file into
memory" }
  ;; Java oriented approach for opening file
  (let [stream (new FileInputStream file-path)
        instr (new LineNumberReader (new InputStreamReader stream))
        ;; Use type hints to ensure a character type.
        readBuffer #^"[C" (make-array (. Character TYPE) 2048)
        buf (new StringBuffer)]
    (loop [n (. instr read readBuffer)]
      (when (> n 0)
        (. buf append readBuffer 0 n)
        (recur (. instr read readBuffer))))
    ;; File info data has been collected, set some of the file
properties
    (set-file-info (. file getName)
                                   (. file getAbsolutePath)
                   (. file lastModified)
                                   (. instr getLineNumber)
                                   (. file getParent)
                   (. file canWrite)
                                   (. file exists)
                                   (. file length))
    (. instr close)
    (. buf toString)))

http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojure/light/toolkit/light_file_utils.clj


Here are some notes from my early analysis, also a google doc on the
functions that are called.
"memory profiling clojure"
http://groups.google.com/group/clojure/browse_thread/thread/b44e25f23d36b08b/296e95f743651949?lnk=gst&q=berlin+brown#296e95f743651949
--~--~---------~--~----~------------~-------~--~----~
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