Arc Forumnew | comments | leaders | submitlogin
5 points by waterhouse 4996 days ago | link | parent

You might find the Scheme/Racket functions "current-memory-use" and "collect-garbage" useful for this kind of thing. And perhaps interesting just to play with.

  ;Assuming ($ x) = "evaluate x in Scheme"
  (mac mem-use body
    (w/uniq x
      `(let ,x ($.current-memory-use)
         ,@body
         (- ($.current-memory-use) ,x))))

  ;In action:
  arc> (mem-use (+ 1 2))
  32
  arc> (mem-use (= x range.10))
  2528
  arc> (mem-use (= x (range 1 10)))
  1680
  arc> x
  (1 2 3 4 5 6 7 8 9 10)
  arc> (mem-use (* 1 2))
  0
  arc> (mem-use ($.collect-garbage))
  -7115280
  arc> (repeat 5 (prn (mem-use:$:collect-garbage)))
  -88828
  -284
  -280
  -280
  -280
  nil


1 point by evanrmurphy 4996 days ago | link

I put ($.collect-garbage) at the top of my defop and tested again. Memory leaks just the same. Somebody in Arcland is forgetting to take the trash out because Scheme has none to collect. :P

Nice macro, by the way. I added it to my utils with an attribution.

-----