##
AST Pointer Contexts—Begin and End

The use of astAnnulastAnnul (§4.9) is not completely foolproof, however. Consider the following:

58#58

This creates a ZoomMapZoomMap and displays it on standard output (§4.4). 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 astZoomMapastZoomMap 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 astBeginastBegin and astEndastEnd, for example:

59#59

When the expansion of astEnd (which is a macro) executes, every ObjectObject 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.