The only safe, consistent, reliable approach is not to deallocate memory.
The only safe, consistent, reliable approach is not to deallocate memory.
Why is tracking the lifetime of a function pointer different from tracking the lifetime of any other pointer?
FreeLibrary on Windows unloads libraries when the reference count is zero.
FYI just loading a DLL can execute code.
> Why is tracking the lifetime of a function pointer different from tracking the lifetime of any other pointer?
Technically speaking none, but historically this is something that nobody did, so we are full of code that assumes function pointers to have a static lifetime. It's a social problem.
The init function could return a status that indicates "already initialized."
The calling code could observe this and passively warn of the unusual condition but otherwise proceed.