aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-01 13:47:37 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-01 13:47:37 -0800
commit6b70b676ba4bdf317c2391e90c82d837b18e3849 (patch)
tree289553d5b7ba414840a6e4024dd48703cd56127f /src
parent8794769222e617f5b35fb77973114d3d4a70dd14 (diff)
misc minor but important memory fixes
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js2
-rw-r--r--src/framework.js8
-rw-r--r--src/intertyper.js3
-rw-r--r--src/jsifier.js8
4 files changed, 14 insertions, 7 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 1b9b4378..edd5c08f 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -15,7 +15,7 @@ function cleanFunc(func) {
function analyzer(data) {
// Substrate
- substrate = new Substrate('Analyzer');
+ var substrate = new Substrate('Analyzer');
// Sorter
substrate.addActor('Sorter', {
diff --git a/src/framework.js b/src/framework.js
index e83250f3..7adf43d3 100644
--- a/src/framework.js
+++ b/src/framework.js
@@ -185,7 +185,7 @@ Substrate.prototype = {
dprint('framework', 'New results: ' + (outputs.length + this.results.length - currResultCount) + ' out of ' + (this.results.length + outputs.length));
hadProcessing = true;
- if (outputs) {
+ if (outputs && outputs.length > 0) {
if (outputs.length === 1 && outputs[0].__finalResult__) {
if (DEBUG) print("Solving complete: __finalResult__");
delete outputs[0].__finalResult__; // Might recycle this
@@ -194,7 +194,6 @@ Substrate.prototype = {
finished = true;
finalResult = outputs[0];
} else {
- outputs.forEach(function(output) { delete output.tokens }); // clean up tokens to save memory
this.results = this.results.concat(outputs);
}
}
@@ -206,7 +205,8 @@ Substrate.prototype = {
delete result.__uid__; // Might recycle these
if (onResult) onResult(result);
});
- ret = this.results;
+ ret = this.results;
+ this.results = null; // No need to hold on to them any more
break;
}
if (finalResult) {
@@ -222,6 +222,8 @@ Substrate.prototype = {
actor.inbox = null;
});
+ if (DEBUG_MEMORY) MemoryDebugger.tick('finished ' + this.name_);
+
return ret;
}
};
diff --git a/src/intertyper.js b/src/intertyper.js
index 45199091..ed2b3fb9 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -2,6 +2,7 @@
// to be processed by the later stages.
var tokenizer; // TODO: Clean this up/out
+ // XXX In particular, this closes over the substrate, which can keep stuff in memory, which is bad
function tokenize(text) {
return tokenizer.processItem({ lineText: text }, true);
}
@@ -30,7 +31,7 @@ function intertyper(data, sidePass, baseLineNum) {
}
}
- substrate = new Substrate('Intertyper');
+ var substrate = new Substrate('Intertyper');
// Line splitter. We break off some bunches of lines into unparsedBundles, which are
// parsed in separate passes later. This helps to keep memory usage low - we can start
diff --git a/src/jsifier.js b/src/jsifier.js
index 09723a27..581df37d 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -45,11 +45,12 @@ function JSify(data, functionsOnly, givenFunctions) {
});
}
- substrate = new Substrate('JSifyer');
+ var substrate = new Substrate('JSifyer');
if (mainPass) {
// Handle unparsed types TODO: Batch them
analyzer(intertyper(data.unparsedTypess[0].lines, true));
+ data.unparsedTypess = null;
// Add additional necessary items for the main pass. We can now do this since types are parsed (types can be used through
// generateStructInfo in library.js)
@@ -100,6 +101,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
});
+ // TODO: batch small functions
for (var i = 0; i < data.unparsedFunctions.length; i++) {
var func = data.unparsedFunctions[i];
// We don't need to save anything past here
@@ -110,6 +112,7 @@ function JSify(data, functionsOnly, givenFunctions) {
if (DEBUG_MEMORY) MemoryDebugger.tick('func ' + func.ident);
}
func = null; // Do not hold on to anything from inside that loop (JS function scoping..)
+ data.unparsedFunctions = null;
// Actors
@@ -231,7 +234,7 @@ function JSify(data, functionsOnly, givenFunctions) {
substrate.addActor('GlobalVariable', {
processItem: function(item) {
item.intertype = 'GlobalVariableStub';
- item.lines = null; // Save some memory
+ assert(!item.lines); // FIXME remove this, after we are sure it isn't needed
var ret = [item];
if (item.ident == '_llvm_global_ctors') {
item.JS = '\n__globalConstructor__ = function() {\n' +
@@ -1096,6 +1099,7 @@ function JSify(data, functionsOnly, givenFunctions) {
// Print out global variables and postsets TODO: batching
JSify(analyzer(intertyper(data.unparsedGlobalss[0].lines, true)), true, Functions);
+ data.unparsedGlobalss = null;
print(Functions.generateIndexing()); // done last, as it may rely on aliases set in postsets
print(postParts[1]);