registerBeforeExit

abstract fun <T : Any> registerBeforeExit(ref: T, callback: (ref: T, event: String) -> Unit)(source)

This function behaves exactly like the register, except that the callback will be called when the process emits the beforeExit event if ref object was not garbage collected.

Be aware that all limitations applied to the beforeExit event are also applied to the callback function, this means that there is a possibility that the callback will not be called under special circumstances.

Since

v22.5.0

Parameters

ref

The reference to the resource that is being tracked.

callback

The callback function to be called when the resource is finalized.