Cleanup Strategy

The support for custom cleanup strategies is based on a template-based implementation of the Strategy design pattern. Cleanup strategies can be specified as an optional template parameter of the class templates for automatic resource management.

Default Cleanup Strategy

The default cleanup strategy is determined by the TResourceCleanupStrategy class template which by default calls a function named Cleanup() function. The DEFINE_CLEANUP_FUNCTION macro defines an inline function named Cleanup() function which is invoked for cleanup of the managed object in place of the default CallCleanupFunction function defined in the header file.


DEFINE_CLEANUP_FUNCTION is provided in order to enable Symbian Developers to easily define the default cleanup member function for a class type, such as an R-class. The macro can be used in the same namespace in which the R-class is defined or in a namespace in which the R-class is used. The DEFINE_CLEANUP_FUNCTION can be used by class designers, but if a class does not have a cleanup function specified, then the class users can use the DEFINE_CLEANUP_FUNCTION in order to define the default cleanup function for that class.

Clean-up Strategy example


This sets the default cleanup behaviour for the RSimple class to be RSimple::ReleaseData(). If this Macro is not used then the default cleanup behaviour would be to call RSimple::Close().