commontk / CTK

A set of common support code for medical imaging, surgical navigation, and related purposes.
https://commontk.org
Apache License 2.0
863 stars 491 forks source link

When I enable the plugin unload, and I watched memory leak in org.commontk.eventadmin #423

Open lygstate opened 10 years ago

lygstate commented 10 years ago

To re-show this issue.

First, enable pluginLoad.unload by use Qt::QueuedConnection, for deal with the possibility that unload a plugin itself in stop function.

// This would unload the shared library and delete the activator if // there are no dependencies. However, objects from the plug-in might // have been created via C-function symbol lookups. Hence we cannot // safely unload the DLL. Maybe implement a in-DLL counter later // (http://stackoverflow.com/questions/460809/c-dll-unloading-issue and // http://boost.2283326.n4.nabble.com/shared-ptr-A-smarter-smart-pointer-proposal-for-dynamic-libraries-td2649749.html). // The activator itself will be delete during program termination // (by the QPluginLoader instance). //TODO: is this method to unload the dll are safe? QMetaObject::invokeMethod((QObject*)&m_unloader, "stopPlugin", Qt::QueuedConnection); //pluginLoader.unload();

Second, at the rutnime, load and unload plugin "org.commontk.eventadmin", then we load that plugin again then the program crash, that's must because of the plugin problems. QVariant didn't support for Q_DECLARE_METATYPE in the dynamic load and unload plugins.

saschazelzer commented 10 years ago

DLL unloading is a tricky business. AFAIK Qt officially doesn't support DLL unloading if meta types are provided by that dll [1]. We could try to work around this, but I am not feeling too confident about that.

[1] https://bugreports.qt-project.org/browse/QTBUG-35935