Re: Allocation/gc for pixmaps
"Krupka Michal (as michal dot krupka at upol dot cz)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
It is a known issue, at least in Mac OS. My naive "solution" would be the following. It seems to work in my case when LW is in foreground.
(defun allocation-test ()
(let ((pane (capi:contain (make-instance 'capi:output-pane))))
(loop for n from 1 to 1000 do
(capi:apply-in-pane-process pane (lambda ()
(gp:with-pixmap-graphics-port (image-port pane 854 480 :background :white :clear t)
;; Clear the pixmap and draw something
(gp:draw-rectangle image-port 0 0 854 480 :foreground :white :filled t)
(gp:draw-string image-port (format nil "Frame ~a" n) 50 50)
(let ((image (gp:make-image-from-port image-port)))
;; ... export the image using e.g. gp:externalize-and-write-image ...
(gp:free-image image-port image)))))
when t ;; or some time has passed
(sleep 0.5 ;; or some other interval
))))
Michal
> 12. 9. 2025 v 17:29, Erik Ronström (as erik dot ronstrom at doremir dot com) <[email protected]>:
>
> Hi,
>
> I’m trying to generate a large number of images which are going to be used to create a video. My problem is that the memory footprint of the lisp image grows for each iteration, despite gp:free-image being called.
>
> I tried to throw in a GC call in the loop, but it seems to have no effect.
>
> Also, placing gp:with-pixmap-graphics-port inside the loop does not help.
>
> What am I missing?
>
> Erik
>
>
> (defun allocation-test ()
> (let ((pane (capi:contain (make-instance 'capi:output-pane))))
> (capi:apply-in-pane-process pane (lambda ()
> (gp:with-pixmap-graphics-port (image-port pane 854 480 :background :white :clear t)
> (loop for n from 1 to 1000 do
>
> ;; Clear the pixmap and draw something
> (gp:draw-rectangle image-port 0 0 854 480 :foreground :white :filled t)
> (gp:draw-string image-port (format nil "Frame ~a" n) 50 50)
>
> ;; Running GC here has no effect
> (when (zerop (mod n 20))
> (gc-generation t))
>
> (let ((image (gp:make-image-from-port image-port)))
>
> ;; ... export the image using e.g. gp:externalize-and-write-image ...
>
> (gp:free-image image-port image))))))))
>
>
>
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> [email protected]
> http://www.lispworks.com/support/lisp-hug.html
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html