void onDestroy(OnDestroyCallback callback)

Allows to register a callback that will be called when the component is destroyed.

Source

void onDestroy(OnDestroyCallback callback);