The use of astAnnul () is not completely
foolproof, however. Consider the following:
astShow( astZoomMap( 2, 5.0, "" ) );
This creates a ZoomMap and displays it on standard output
(). Using function invocations as
arguments to other functions in this way is very convenient because it
avoids the need for intermediate pointer variables. However, the
pointer generated by astZoomMap is still active, and since we have not
stored its value, we cannot use astAnnul to annul it. The ZoomMap will
therefore stay around until the end of the program.
A simple way to avoid this problem is to enclose all use of AST functions between invocations of astBegin and astEnd, for example:
astBegin; astShow( astZoomMap( 2, 5.0, "" ) ); astEnd;
When the expansion of astEnd (which is a macro) executes, every Object pointer created since the previous use of astBegin (also a macro) is automatically annulled and any Objects left without pointers are deleted. This provides a simple solution to managing Objects and their pointers, and allows you to create Objects very freely without needing to keep detailed track of each one. Because this is so convenient, we implicitly assume that astBegin and astEnd are used in most of the examples given in this document. Pointer management is not generally shown explicitly unless it is particularly relevant to the point being illustrated.
If necessary, astBegin and astEnd may be nested, like blocks delimited by ``{...}'' in C, to define a series of AST pointer contexts. Each use of astEnd will then annul only those Object pointers created since the matching use of astBegin.
AST A Library for Handling World Coordinate Systems in Astronomy