[Q&A] SYCL objects are still alive while the runtime is shutting down

When developing your SYCL application, you may or may not have come across this SYCL runtime error:

SYCL objects are still alive while the runtime is shutting down.

The error message clearly indicates that there are SYCL objects haven’t been destroyed properly when exiting of the main program scope.

But you may be wondering what could have caused this error. At this stage, ComputeCpp doesn’t know what’s going on and assumes that either:

  • You have proceeded further down your program logic and haven’t waited for something to happen (that you should have waited for).
  • You are destroying an object in a non-standard (recommended) way, such that ComputeCpp cannot provide a more concrete exception handling for.

More specifically, the reason for this behavior can be caused by bad destruction, unnatural abortion of the program or a segfaulting piece of code somewhere else in the application (or in external dependency of the application).

Bad destruction: Mismatched new/delete pairing or preventing the destructors of a SYCL object from being called.

Unnatural abortion of the program: Calling any of exit(), terminate(), abort() system calls which will terminate the calling process without executing the rest code which is after that call.

Segfaulting code: Some (other) code in the application that produces segfault during run-time. In this case, ComputeCpp just doesn’t know so the runtime informs us that something that doesn’t seem right.