summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-09-29 11:29:44 -0400
committerDavid Thompson <dthompson2@worcester.edu>2020-09-29 11:29:44 -0400
commit95be967547cdaad47e2eb1e375d7dda68aa34659 (patch)
tree4dbd8e8cf26b9670bf8e15d4106e158f22714410
parentdcec0300b471b424d8f466c181af6ee1fc53f8e6 (diff)
array-list: Clear old elements so they can be GC'd.
-rw-r--r--chickadee/array-list.scm9
1 files changed, 9 insertions, 0 deletions
diff --git a/chickadee/array-list.scm b/chickadee/array-list.scm
index 54a11e8..3b11ec1 100644
--- a/chickadee/array-list.scm
+++ b/chickadee/array-list.scm
@@ -93,10 +93,19 @@
(define (array-list-pop! array-list)
(let* ((index (1- (array-list-size array-list)))
(item (array-list-ref array-list index)))
+ ;; Remove element reference so it can be GC'd.
+ (array-list-set! array-list index #f)
(set-array-list-size! array-list index)
item))
(define (array-list-clear! array-list)
+ (let ((size (array-list-size array-list))
+ (vec (array-list-vector array-list)))
+ ;; Remove all element references so they can be GC'd.
+ (let loop ((i 0))
+ (when (< i size)
+ (vector-set! vec i #f)
+ (loop (1+ i)))))
(set-array-list-size! array-list 0)
*unspecified*)