I used the QGIS Plugin Builder to create a plugin where the main.py file imports dockwidgets and class from its own file and from other files. A button on the toolbar executes the run(self)
function in main.py where it loads the imported dockwidgets, classes, connecting buttons to functions etc.
Another button on the toolbar closes the plugin by executing the onClosePlugin(self)
function. This function only closes dockwidgets loaded from main.py (so not from other files) and disconnects its buttons. The imported classes are untouched. However, when I close the plugin, QGIS continues to run but a lot slower than usual. It also takes longer to close down, sometimes I get an error report. I'm guessing this is because of all the resources my plugin loads but is still in memory when the plugin is closed.
How can I remove/unload all resources that have been imported/loaded by the plugin?
When I import dockwidgets and classes from other files, I use the following in my main.py
from some_Dockwidget import someDockwidget
from general_Class import generalClass
Which are then called in run(self)
:
self.someDockwidget = someDockwidget()
self.generalClass = generalClass()
I found this post which closes all QDialog boxes. I have used the following to close all dockwidgets but can it be adapted to close/unload/delete everything that has been imported/loaded?
items = vars(self)
for i in items:
item = items[i]
if isinstance(item, QDockWidget):
item.close()