Unload plugins at shutdown, fix memory leaks
Note that this might require changes in 3rd party plugins as unloading happens very late. See e.g. 485db2e87 and fca70af3b.