Programmer Reference : Common Graphics : Resource management summary
Resource management summary
Most Common Graphics resources need to be explicitly deallocated when no longer required, otherwise operating system resources are lost and will eventually run out. This includes fonts, pixmaps, color cells, graphics contexts, cursors, and icons.
Often the best place to deallocate graphics resources is in a destroy callback handler for the drawing area widget in which graphics are being drawn. See "Drawing area widgets" for more information.
The following table summarizes when and how to free graphics objects allocated by the application:
Table 27. Graphics object freeing reference
Graphics object
Summary
 
CgCursor
Obtained using:
CgDisplay>>createFontCursor
CgPixmap>>createPixmapCursor
CgFont>>createGlyphCursor
CgCursor
Freed using:
CgCursor>>freeCursor
CgCursor
When to free:
When it will no longer be set as the cursor for any window (using CgWindow>>setWindowCursor:). Cursors are normally allocated when an application is opened and freed when it is closed.
CgDeviceIndependentImage
Obtained using:
CgDeviceIndependentImage class>> width:height:depth:palette: width:height:depth:palette:scanlinePad:data:
CgDeviceIndependentImage
Freed using:
<None>
CgDeviceIndependentImage
When to free:
Images do not need to be explicitly freed.
CgDirectPalette
Obtained using:
CgDirectPalette class>> redMask:greenMask:blueMask:
CgDirectPalette
Freed using:
<None>
CgDirectPalette
When to free:
Direct palettes do not need to be explicitly freed.
CgGC
Obtained using:
CgWindow>>createGC:
CgGC
Freed using:
CgGC>>freeGC
CgGC
When to free:
When it is no longer required for graphics operations on the drawable for which it was created. It is typically freed when a window is closed by hooking the destroy callback.
CgFont
Obtained using:
CgDisplay>>loadFont:
CgFont
Freed using:
CgFont>>unloadFont
CgFont
When to free:
When it is no longer required for graphics operations on any drawable. It is typically freed when no more text will be drawn with that font. The font can remain selected in a CgGC but if a request using the font is made, such as drawing a string, the results are undefined.
CgFontStruct
Obtained using:
CgDisplay>>loadQueryFont: CgFont>>queryFont
CgFontStruct
Freed using:
CgFontStruct>>freeFont
CgFontStruct
When to free:
When it is no longer required for information about its font and when no more text will be drawn with that font. The same conditions as for freeing CgFont apply.
CgIndexedPalette
Obtained using:
CgIndexedPalette class>> entries: colors:
CgIndexedPalette
Freed using:
<None>
CgIndexedPalette
When to free:
Indexed palettes do not need to be explicitly freed.
CgIcon
Obtained using:
CgIcon class>>
fromImage:maskImage:
fromOSIcon:
fromResource:
fromResource:fileName
fromResources:
fromResources:fileName:
fromSystem:
width:height:depth:palette:shapePad:- shapeData:maskPad:maskData:
CgIcon
Freed using:
CgIcon>>freeIcon
CgIcon
When to free:
When it will no longer be drawn and it is no longer set as an icon resource of a widget.
CgPixmap
Obtained using:
CgDrawable>>createPixmap: createBitmapFromData: createPixmapFromBitmapData: readBitmapFile:
CgPixmap
Freed using:
CgPixmap>>freePixmap
CgPixmap
When to free:
When it will no longer be used for drawing on, it will no longer be used as the source for a copy operation, and it will no longer be used as a tile or stipple pattern in a GC.
CgArc, CgCharStruct, CgFontProp, CgGCValues, CgRGBColor, CgSegment, CgTextItem
Obtained using:
<Misc>
CgArc, CgCharStruct, CgFontProp, CgGCValues, CgRGBColor, CgSegment, CgTextItem
Freed using:
<None>
CgArc, CgCharStruct, CgFontProp, CgGCValues, CgRGBColor, CgSegment, CgTextItem
When to free:
These objects are informational data structures only, and need not be explicitly freed.
 
 
Last modified date: 05/13/2020