It depends how that memory was allocated and whether the mechanism to do so ("the runtime" or "memory manager") is shared between the specific DLL and the other parts of the application. E.g. a throw new my_exception( args );
could also be in order depending on the details.
You could make your exception reference counted, so that it comes with the intrinsic knowledge of how to destroy its own instance (and owned memory).
Using IMalloc
(see MSDN) for instance allocation and placement new
would be another way (call OleInitialize
before) ...
Indeed, the memory allocation is an issue depending on what is being used. For example mixing statically linked CRT and dynamically linked CRT in different parts of an application will lead to issues the same way the mixing debug and release code would. The problem here is that the code that is supposed to free the memory uses a different "memory manager". But if the thrown object knows about its own destruction, it should be fine, since the dtor code would reside in the same compilation unit as the one allocating it.