[Bf-blender-cvs] [3a28e7c] depsgraph_refactor: Depsgraph: Use explicit guarded allocation macros

Sergey Sharybin noreply at git.blender.org
Mon Dec 8 13:02:43 CET 2014


Commit: 3a28e7cc1f5555e8c2e8b18c0d3e16d69700b7b0
Author: Sergey Sharybin
Date:   Mon Dec 8 17:00:33 2014 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rB3a28e7cc1f5555e8c2e8b18c0d3e16d69700b7b0

Depsgraph: Use explicit guarded allocation macros

This way we always are keeping track on memory usage of the depsgraph
(as opposite to previous: only when GXX guarded allocator is enabled,
which isn't enabled i.e. for release builds).

Allows us to track memory leaks earlier, plus allows us to keep an eye
on the memory usage of the graph itself.

===================================================================

M	source/blender/depsgraph/intern/depsgraph.cpp
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build.cpp
M	source/blender/depsgraph/intern/depsgraph_intern.h
M	source/blender/depsgraph/intern/depsnode.cpp
M	source/blender/depsgraph/intern/depsnode.h
M	source/blender/depsgraph/intern/depsnode_component.cpp
M	source/blender/depsgraph/intern/depsnode_operation.cpp

===================================================================

diff --git a/source/blender/depsgraph/intern/depsgraph.cpp b/source/blender/depsgraph/intern/depsgraph.cpp
index 3e6b1a8..0298134 100644
--- a/source/blender/depsgraph/intern/depsgraph.cpp
+++ b/source/blender/depsgraph/intern/depsgraph.cpp
@@ -51,7 +51,7 @@ Depsgraph::~Depsgraph()
 {
 	/* free root node - it won't have been freed yet... */
 	if (this->root_node) {
-		delete this->root_node;
+		OBJECT_GUARDED_DELETE(this->root_node, RootDepsNode);
 	}
 	
 	clear_id_nodes();
@@ -192,14 +192,14 @@ SubgraphDepsNode *Depsgraph::add_subgraph_node(const ID *id)
 void Depsgraph::remove_subgraph_node(SubgraphDepsNode *subgraph_node)
 {
 	subgraphs.erase(subgraph_node);
-	delete subgraph_node;
+	OBJECT_GUARDED_DELETE(subgraph_node, SubgraphDepsNode);
 }
 
 void Depsgraph::clear_subgraph_nodes()
 {
 	for (Subgraphs::iterator it = subgraphs.begin(); it != subgraphs.end(); ++it) {
 		SubgraphDepsNode *subgraph_node = *it;
-		delete subgraph_node;
+		OBJECT_GUARDED_DELETE(subgraph_node, SubgraphDepsNode);
 	}
 	subgraphs.clear();
 }
@@ -229,8 +229,7 @@ void Depsgraph::remove_id_node(const ID *id)
 	if (id_node) {
 		/* unregister */
 		this->id_hash.erase(id);
-		
-		delete id_node;
+		OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
 	}
 }
 
@@ -238,7 +237,7 @@ void Depsgraph::clear_id_nodes()
 {
 	for (IDNodeMap::const_iterator it = id_hash.begin(); it != id_hash.end(); ++it) {
 		IDDepsNode *id_node = it->second;
-		delete id_node;
+		OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
 	}
 	id_hash.clear();
 }
@@ -249,7 +248,7 @@ DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from, OperationDeps
                                           const string &description)
 {
 	/* create new relation, and add it to the graph */
-	DepsRelation *rel = new DepsRelation(from, to, type, description);
+	DepsRelation *rel = OBJECT_GUARDED_NEW(DepsRelation, from, to, type, description);
 	return rel;
 }
 
@@ -318,13 +317,13 @@ void Depsgraph::add_entry_tag(OperationDepsNode *node)
 /* Initialise a new Depsgraph */
 Depsgraph *DEG_graph_new()
 {
-	return new Depsgraph;
+	return OBJECT_GUARDED_NEW(Depsgraph);
 }
 
 /* Free graph's contents and graph itself */
 void DEG_graph_free(Depsgraph *graph)
 {
-	delete graph;
+	OBJECT_GUARDED_DELETE(graph, Depsgraph);
 }
 
 /* ************************************************** */
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 2c71034..6a94105 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -84,10 +84,6 @@ struct DepsRelation {
 	
 	DepsRelation(OperationDepsNode *from, OperationDepsNode *to, eDepsRelation_Type type, const string &description);
 	~DepsRelation();
-	
-#ifdef WITH_CXX_GUARDEDALLOC
-	MEM_CXX_CLASS_ALLOC_FUNCS("DEG:DepsNode")
-#endif
 };
 
 /* ************************************* */
@@ -164,10 +160,6 @@ struct Depsgraph {
 	OperationNodes operations; /* all operation nodes, sorted in order of single-thread traversal order */
 	
 	// XXX: additional stuff like eval contexts, mempools for allocating nodes from, etc.
-	
-#ifdef WITH_CXX_GUARDEDALLOC
-	MEM_CXX_CLASS_ALLOC_FUNCS("DEG:DepsNode")
-#endif
 };
 
 /* Helper macros for interating over set of relationship
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index 5cc2bb3..4210a84 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -434,7 +434,7 @@ static void deg_graph_transitive_reduction(Depsgraph *graph)
 			++it_rel; /* increment in advance, so we can safely remove the relation */
 			
 			if (rel->from->done & OP_REACHABLE) {
-				delete rel;
+				OBJECT_GUARDED_DELETE(rel, DepsRelation);
 			}
 		}
 	}
diff --git a/source/blender/depsgraph/intern/depsgraph_intern.h b/source/blender/depsgraph/intern/depsgraph_intern.h
index 9020ade..6ae38d1 100644
--- a/source/blender/depsgraph/intern/depsgraph_intern.h
+++ b/source/blender/depsgraph/intern/depsgraph_intern.h
@@ -110,7 +110,7 @@ struct DepsNodeFactoryImpl : public DepsNodeFactory {
 	
 	DepsNode *create_node(const ID *id, const string &subdata, const string &name) const
 	{
-		DepsNode *node = new NodeType();
+		DepsNode *node = OBJECT_GUARDED_NEW(NodeType);
 		
 		/* populate base node settings */
 		node->type = type();
@@ -131,7 +131,7 @@ struct DepsNodeFactoryImpl : public DepsNodeFactory {
 	virtual DepsNode *copy_node(DepsgraphCopyContext *dcc, const DepsNode *copy) const
 	{
 		BLI_assert(copy->type == type());
-		DepsNode *node = new NodeType();
+		DepsNode *node = OBJECT_GUARDED_NEW(NodeType);
 		
 		/* populate base node settings */
 		node->type = type();
diff --git a/source/blender/depsgraph/intern/depsnode.cpp b/source/blender/depsgraph/intern/depsnode.cpp
index 05625ea..f623b78 100644
--- a/source/blender/depsgraph/intern/depsnode.cpp
+++ b/source/blender/depsgraph/intern/depsnode.cpp
@@ -90,7 +90,7 @@ void TimeSourceDepsNode::add_new_relation(OperationDepsNode *to)
 
 RootDepsNode::~RootDepsNode()
 {
-	delete time_source;
+	OBJECT_GUARDED_DELETE(time_source, TimeSourceDepsNode);
 }
 
 TimeSourceDepsNode *RootDepsNode::add_time_source(const string &name)
@@ -180,8 +180,7 @@ void IDDepsNode::remove_component(eDepsNode_Type type, const string &name)
 	if (comp_node) {
 		/* unregister */
 		this->components.erase(key);
-		
-		delete comp_node;
+		OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
 	}
 }
 
@@ -189,7 +188,7 @@ void IDDepsNode::clear_components()
 {
 	for (ComponentMap::const_iterator it = components.begin(); it != components.end(); ++it) {
 		ComponentDepsNode *comp_node = it->second;
-		delete comp_node;
+		OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
 	}
 	components.clear();
 }
diff --git a/source/blender/depsgraph/intern/depsnode.h b/source/blender/depsgraph/intern/depsnode.h
index 5dd8126..346e2bf 100644
--- a/source/blender/depsgraph/intern/depsnode.h
+++ b/source/blender/depsgraph/intern/depsnode.h
@@ -72,10 +72,6 @@ public:
 	virtual void copy(DepsgraphCopyContext *dcc, const DepsNode *src) {}
 	
 	virtual void tag_update(Depsgraph *graph) {}
-	
-#ifdef WITH_CXX_GUARDEDALLOC
-	MEM_CXX_CLASS_ALLOC_FUNCS("DEG:DepsNode")
-#endif
 };
 
 /* Macros for common static typeinfo */
diff --git a/source/blender/depsgraph/intern/depsnode_component.cpp b/source/blender/depsgraph/intern/depsnode_component.cpp
index 30be003..647ed5d 100644
--- a/source/blender/depsgraph/intern/depsnode_component.cpp
+++ b/source/blender/depsgraph/intern/depsnode_component.cpp
@@ -117,8 +117,7 @@ void ComponentDepsNode::remove_operation(const string &name)
 	if (op_node) {
 		/* unregister */
 		this->operations.erase(name);
-		
-		delete op_node;
+		OBJECT_GUARDED_DELETE(op_node, OperationDepsNode);
 	}
 }
 
@@ -126,7 +125,7 @@ void ComponentDepsNode::clear_operations()
 {
 	for (OperationMap::const_iterator it = operations.begin(); it != operations.end(); ++it) {
 		OperationDepsNode *op_node = it->second;
-		delete op_node;
+		OBJECT_GUARDED_DELETE(op_node, OperationDepsNode);
 	}
 	operations.clear();
 }
diff --git a/source/blender/depsgraph/intern/depsnode_operation.cpp b/source/blender/depsgraph/intern/depsnode_operation.cpp
index 917ee6f..f8e8048 100644
--- a/source/blender/depsgraph/intern/depsnode_operation.cpp
+++ b/source/blender/depsgraph/intern/depsnode_operation.cpp
@@ -54,11 +54,11 @@ OperationDepsNode::~OperationDepsNode()
 	 * but only touch the same position as we are using here, which is safe.
 	 */
 	DEPSNODE_RELATIONS_ITER_BEGIN(this->inlinks, rel)
-		delete rel;
+		OBJECT_GUARDED_DELETE(rel, DepsRelation);
 	DEPSNODE_RELATIONS_ITER_END;
 	
 	DEPSNODE_RELATIONS_ITER_BEGIN(this->outlinks, rel)
-		delete rel;
+		OBJECT_GUARDED_DELETE(rel, DepsRelation);
 	DEPSNODE_RELATIONS_ITER_END;
 }




More information about the Bf-blender-cvs mailing list