An enclave is used by an application. How can the enclave know that the application has been terminated if the application crashes before or without calling sgx_destroy_enclave?
Enclaves are part of the application. If the application terminates then the enclave also destroyed.
For more complete information about compiler optimizations, see our Optimization Notice.