Re: Gradual Growth of Memory Use?

"Tim Bradshaw (as tfb at tfeb dot org)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
I'm still a bit surprised that I can't see any record of anyone trying to find out what's actually leaking all the space: what are the objects which are being leaked?

In case it's useful, below is a little function I have which will tell things about the numbers, size and cumulative size used by objects of various classes.

So for instance:

> (size-by-class/loop :min-ratio 0.1)
(#S(class-counter :name clos::system-object
                  :count 62905
                  :total-size 16011504
                  :cumulative-size 58028128)
 #S(class-counter :name simple-vector
                  :count 196765
                  :total-size 12461608
                  :cumulative-size 42016624)
 #S(class-counter :name cons
                  :count 543444
                  :total-size 8695104
                  :cumulative-size 29555016)
 #S(class-counter :name function
                  :count 55235
                  :total-size 4137200
                  :cumulative-size 20859912)
 #S(class-counter :name simple-string
                  :count 5284
                  :total-size 3197472
                  :cumulative-size 16722712)
 #S(class-counter :name symbol
                  :count 66540
                  :total-size 3193920
                  :cumulative-size 13525240)
 #S(class-counter :name simple-base-string
                  :count 89436
                  :total-size 3062872
                  :cumulative-size 10331320)
 #S(class-counter :name double-float
                  :count 97398
                  :total-size 1558368
                  :cumulative-size 7268448))

Note this has been converted from the version I actually use, which uses Štar, to something using loop.  The translation might be buggy.  I will now have to do penance for using loop.

--tim

--cut--

(in-package :cl-user)

(defstruct class-counter
  name
  (count 0)
  (total-size 0)
  (cumulative-size 0))

(defun size-by-class/loop (&key (gen-0 nil) (min-ratio nil) (test nil))
  (let ((stab (make-hash-table)))
    (sweep-all-objects
     (lambda (o)
       (when (if test (funcall test o) t)
         (let* ((c (class-name (class-of o)))
                (cc (or (gethash c stab)
                        (setf (gethash c stab) (make-class-counter :name c)))))
           (incf (class-counter-total-size cc) (find-object-size o))
           (incf (class-counter-count cc)))))
     gen-0)
    (let ((cumulative
           (nreverse
            (loop for cct on (sort (loop for cc being the hash-values of stab
                                         collect cc)
                                   #'<
                                   :key #'class-counter-total-size)
                  for cc = (first cct)
                  summing (if cc (class-counter-total-size cc) 0) into a
                  do (setf (class-counter-cumulative-size cc) a)
                  collect cc))))
      (if min-ratio
          (let ((total (class-counter-cumulative-size (first cumulative))))
            (ldiff cumulative (member-if (lambda (size)
                                           (< (/ size total) min-ratio))
                                         cumulative
                                         :key #'class-counter-cumulative-size)))
        cumulative))))

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.