Navigation:  Programming Cookbook > External Interfacing > External Callbacks >

Callback Lifetime

Previous pageReturn to chapter overviewNext page

Callbacks can be either synchronous, in which case the callback will only be invoked during the lifetime of the relevant external library call, EnumFonts() being an example, or asynchronous, in which case the callback is captured and registered for use whenever it is required, until the registration is revoked.

Synchronous callbacks are the more common and easier case since the lifetime of the callback object is known. Synchronous callbacks can be explicitly freed once the external call has returned.

Asynchronous callbacks capture the callback object, and hence it is necessary to maintain a reference (generally in an instance variable) to the ExternalCallback for the lifetime of the registration in order that it not be garbage collected. Asynchronous callbacks are normally implicitly freed by  finalizationwhen no longer required.