Path: utzoo!attcan!uunet!husc6!bloom-beacon!ZERMATT.LCS.MIT.EDU!RWS From: RWS@ZERMATT.LCS.MIT.EDU (Robert Scheifler) Newsgroups: comp.windows.x Subject: Question on creation on gc's Message-ID: <19880525202650.1.RWS@KILLINGTON.LCS.MIT.EDU> Date: 25 May 88 20:26:00 GMT References: <8805252012.AA20876@nrl-aic.arpa> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 23 Date: Wed, 25 May 88 16:12:17 EDT From: Alan Schultz (defun some-simple-graphics-primitive (x y color) (let ((gc (create-gcontext :drawable *window* :foreground color))) (draw-rectangle *window* gc x y *width* *height*)) ) QUESTION: Is the above expensive? Or since the gc is assigned to a temporary variable, is it freed up after the function returns? GC's are *not* freed just because the local variable binding goes away. You are creating many resources in the server, and never freeing them. This is very expensive, and eventually you will run out of resource ids or memory. I have MANY such functions that get called OFTEN. Is it better to create one gc at the top level, and then modify it as necessary Yes, much better. Take a look at the WITH-GCONTEXT macro, which provides a dynamic binding mechanism (that C is sorely in need of).