How to deinitialize OCCT

I am developing a Delphi application using a OCCT through a wrapper DLL with c-style exports.

While this approach works reasonably well, i have some issues with deinitializing the OCCT-Modules.
The application ( a construction/calculation suite for architectural engineering) is using OCCT for modeling and export of 3d-assemblies from paramters stored in it's database, so the OCCT-module is not needed permanently.

the typical workflow is:

  1. Generate construction
  2. Load Wrapper Dll
  3. initalize a viewer
  4. model the construction as an OCCT-Assembly
  5. Export to file
  6. unload wrapper DLL

The wrapper DLL is loaded dynamically, but is itself load-time-linked to the OCCT libraries using the lib files and headers provided by the OpenCascasde installation.

After the unloading the wrapper dll, some (but not all) of the Opencascade dlls stay loaded into my processes memory space. I experimented wiht delay-loading and explicitly unloading the libraries, but had no change in behaviour.

This wouldn't be so bad since the dlls are unloaded once my application process terminates. BUT, when the application starts generation and modeling of second construction, it crasges or freezes, either during the initialization of a new viewer, or when modeling the required shapes.

I would guess that some of the TK*.dlls have internal states which I don't reset when unloading my wrapper. Could anyone give me some hints as how to truly unload all OCCT components from my process?

m-sazonov's picture

Hi Tilman,
Unfortunately, it is impossible to correctly unload OCCT DLLs from memory. There are a lot of static variables that are initialized with loading of DLLs, and they are never destroyed.
So, in the current time, it is better to leave them in memory.
Mikhail

Tilman Leune's picture

Thank you for that bit of information.

I'll have to build myself a workarond, then.