Images and memory
Hi folks, I use an output-pane to display a list of files, together with a preview of each file. Naturally, I want to cache the previews rather than creating them from scratch every time they are to be drawn. The question is – how can this be done in a safe way, i.e. without memory leaks? According to the CAPI documentation, images need to be freed after use. This is done implicitly when the port used to create them is destroyed, but in this case that won't happen until the program quits. The list items are represented by objects, and in another language I would have used the destructor of that class to free the contained images. In Lisp I don't have that option. Is there any point in externalizing the images and loading them at draw time? The documentation doesn't say anything about freeing external images, and I don't know if that means that they don't have to be explicitly freed, or that the documentation just don't mention it. Follow-up questions: 1) Does the following code leak memory (as the loaded image is not freed after use)? 2) Is the image loaded at every redraw, or is it cached somehow? (defun load-function () (setf *external-image* (gp:read-external-image "some-image.png"))) (defun output-pane-draw-function (pane x y w h) (gp:draw-image pane (gp:load-image pane *external-image*) 0 0)) Best regards Erik _______________________________________________ Lisp Hug - the mailing list for LispWorks users lisp-hug@lispworks.com http://www.lispworks.com/support/lisp-hug.html