Add debug flag to fix compute graph memory leak

mfw no destructor hook
This commit is contained in:
hppeng 2022-07-20 12:06:34 -07:00
parent a364cb0fc7
commit 75f4fc684b
2 changed files with 7 additions and 5 deletions

View file

@ -1376,6 +1376,7 @@
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/build_utils.js"></script>
<script type="text/javascript" src="../js/computation_graph.js"></script>
<script type="text/javascript">COMPUTE_GRAPH_DEBUG=true;</script>
<!-- <script type="text/javascript" src="../js/icons.js"></script> -->
<script type="text/javascript" src="../js/sq2icons.js"></script>
<script type="text/javascript" src="../js/powders.js"></script>

View file

@ -1,5 +1,6 @@
let all_nodes = [];
let all_nodes = new Set();
let node_debug_stack = [];
let COMPUTE_GRAPH_DEBUG = false;
class ComputeNode {
/**
* Make a generic compute node.
@ -21,7 +22,7 @@ class ComputeNode {
// 0: clean
this.inputs_dirty = new Map();
this.inputs_dirty_count = 0;
all_nodes.push(this);
if (COMPUTE_GRAPH_DEBUG) { all_nodes.add(this); }
}
/**
@ -34,7 +35,7 @@ class ComputeNode {
if (this.dirty === 0) {
return;
}
node_debug_stack.push(this.name);
if (COMPUTE_GRAPH_DEBUG) { node_debug_stack.push(this.name); }
if (this.dirty == 2) {
let calc_inputs = new Map();
for (const input of this.inputs) {
@ -46,7 +47,7 @@ class ComputeNode {
for (const child of this.children) {
child.mark_input_clean(this.name, this.value);
}
node_debug_stack.pop();
if (COMPUTE_GRAPH_DEBUG) { node_debug_stack.pop(); }
return this;
}
@ -190,7 +191,7 @@ function calcSchedule(node, timeout) {
}
node.mark_dirty();
node.update_task = setTimeout(function() {
node_debug_stack = [];
if (COMPUTE_GRAPH_DEBUG) { node_debug_stack = []; }
node.update();
node.update_task = null;
}, timeout);