[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AppleEvent/Eval-Server memory leak?



Greetings!

The following is a dribble output of an example in the eval-server.lisp. 
The code inside function #'ae-test is copied directly from the examples 
in eval-server.lisp. Notice the problem that the Mac Heap decreases 36 
bytes for each call to #'ae-test. If it is called many times, it is 
clear that the Mac Heap loses more memory. Replacing the parameter 
"(+ 1 2)" with "(* 100 200)", the Mac Heap lost 40 bytes every time. 
The expanded code of #'with-aedescs shown as the following,

(let* ((event (%new-ptr 8 nil)) 
       (reply (%new-ptr 8 nil)) 
       (target (%new-ptr 8 nil)))
  (declare (dynamic-extent target reply event))
  (declare (type macptr target reply event))
  (declare (unsettable target reply event))
  (setf (%get-ptr event 4) (%null-ptr))
  (setf (%get-ptr reply 4) (%null-ptr))
  (setf (%get-ptr target 4) (%null-ptr))
  (unwind-protect
      (progn
        (create-self-target target)
        (create-appleevent event :|misc| :|dosc| target)
        (ae-put-parameter-char event traps::$keydirectobject "(+ 1 2)")
        (send-appleevent event reply :reply-mode :wait-reply)
        (ae-get-parameter-char reply traps::$keydirectobject t))
    (unless (%null-ptr-p (rref event aedesc.datahandle))
      (require-trap traps:_aedisposedesc event))
    (unless (%null-ptr-p (rref reply aedesc.datahandle))
      (require-trap traps:_aedisposedesc reply))
    (unless (%null-ptr-p (rref target aedesc.datahandle))
      (require-trap traps:_aedisposedesc target))))

seems ok. So where did the memory go?


The following is the dribble output of the session:
-------------------------------------------------------------------

#<output output-file-stream to "KSQ402:MCL 2.0:AE-Prob.txt">
? (load "ccl:examples;appleevent-toolkit")
;Loading #4P"ccl:examples;appleevent-toolkit.fasl"...
#P"KSQ402:MCL 2.0:examples:appleevent-toolkit.fasl"
? (load "ccl:examples;eval-server")
;Loading #4P"ccl:examples;eval-server.lisp"...
#P"KSQ402:MCL 2.0:examples:eval-server.lisp"
? (defun ae-test ()
    (with-aedescs (event reply target)
      (create-self-target target)
      (create-appleevent event :|misc| :|dosc| target)
      (ae-put-parameter-char event #$keyDirectObject "(+ 1 2)")
      (send-appleevent event reply :reply-mode :wait-reply)
      (ae-get-parameter-char reply #$keyDirectObject t)
      ))
ae-test
? (gc)
nil
? (room t)
There are at least 6063908 bytes of available RAM.

                  Total Size            Free               Used
Mac Heap:       759580 (741K)       334148 (326K)       425432 (416K)
Lisp Heap:     6774784 (6616K)      5729760 (5595K)      1046128 (1021K)
 (Static):      528384 (516K)
Stacks:         208932 (204K)
Markable objects:      969000 (946K) dynamic, 223400 (218K) static.
Immediate objects:      77128 (75K) dynamic, 304688 (297K) static.
? (ae-test)
"3"
? (gc)
nil
? (room t)
There are at least 6065088 bytes of available RAM.

                  Total Size            Free               Used
Mac Heap:       759580 (741K)       334112 (326K)       425468 (416K)
Lisp Heap:     6774784 (6616K)      5730976 (5596K)      1044912 (1020K)
 (Static):      528384 (516K)
Stacks:         208932 (204K)
Markable objects:      968232 (945K) dynamic, 223400 (218K) static.
Immediate objects:      76680 (74K) dynamic, 304688 (297K) static.
? (dotimes (i 100) (ae-test))
nil
? (gc)
nil
? (room t)
There are at least 6061940 bytes of available RAM.

                  Total Size            Free               Used
Mac Heap:       759580 (741K)       329572 (321K)       430008 (420K)
Lisp Heap:     6774784 (6616K)      5732368 (5598K)      1045304 (1020K)
 (Static):      528384 (516K)
Stacks:         208932 (204K)
Markable objects:      968304 (945K) dynamic, 223400 (218K) static.
Immediate objects:      77000 (75K) dynamic, 304688 (297K) static.
? (dotimes (i 1000) (ae-test))
nil
? (gc)
nil
? (room t)
There are at least 6015940 bytes of available RAM.

                  Total Size            Free               Used
Mac Heap:       759580 (741K)       285092 (278K)       474488 (464K)
Lisp Heap:     6774784 (6616K)      5730848 (5596K)      1045040 (1020K)
 (Static):      528384 (516K)
Stacks:         208932 (204K)
Markable objects:      968304 (945K) dynamic, 223400 (218K) static.
Immediate objects:      76736 (74K) dynamic, 304688 (297K) static.
? (dribble)

-------------------------------------------------------------------

Hai Wang
RSTAR, Inc.
doyle@sisu.mgh.harvard.edu