Material: Fix several memory leaks caused by cyclic references
The class MaterialLibrary has a shared pointer to its Material objects and the class Material has a shared pointer to the MaterialLibrary. The class MaterialManager owns all MaterialLibrary and Material objects in static containers. To resolve the cyclic references the method cleanup() has been added. The class ModelLibrary has a shared pointer to its Model objects and the class Model has a shared pointer to the ModelLibrary. The class ModelManager owns all ModelLibrary and Model objects in static containers. To resolve the cyclic references the method cleanup() has been added. The Materials module registers a function to App::CleanupProcess that calls the above cleanup() methods. NOTE: This registration is only done in debug mode mainly to satisfy memory checkers
This commit is contained in:
@@ -27,7 +27,10 @@
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/PyObjectBase.h>
|
||||
|
||||
#include <App/CleanupProcess.h>
|
||||
|
||||
#include "MaterialFilterPy.h"
|
||||
#include "MaterialLoader.h"
|
||||
#include "MaterialManagerPy.h"
|
||||
#include "MaterialPy.h"
|
||||
#include "ModelManagerPy.h"
|
||||
@@ -61,6 +64,12 @@ PyObject* initModule()
|
||||
|
||||
PyMOD_INIT_FUNC(Materials)
|
||||
{
|
||||
#ifdef FC_DEBUG
|
||||
App::CleanupProcess::registerCleanup([](){
|
||||
Materials::MaterialManager::cleanup();
|
||||
Materials::ModelManager::cleanup();
|
||||
});
|
||||
#endif
|
||||
PyObject* module = Materials::initModule();
|
||||
|
||||
Base::Console().Log("Loading Material module... done\n");
|
||||
|
||||
Reference in New Issue
Block a user