jsx/JSX — pull request #234 by gfx (2013-08-09 01:59:08+00:00)
Title: add --enable-release-vars to release variables not captured in closures

Added an optional feature to release variables; however, it might not be worth merging if major JS environments have this feature; at least the latest V8 and JavaScriptCore has the exactly same feature. What do you think of it?

### Description of the memory benchmark program

See node_example/node_example/memory-usage-with-closures.jsx which reports memory usage for environment capturing in closures.

https://github.com/jsx/JSX/blob/gfx/release-unbound-vars/node_example/memory-usage-with-closures.jsx

showing a report like this:

```
$ jsx --run --enable-release-vars node_example/memory-usage-with-closures.jsx
42 MiB**************
56 MiB*******************
63 MiB*********************
77 MiB**************************
90 MiB******************************
103 MiB***********************************
62 MiB*********************
76 MiB**************************
89 MiB******************************
60 MiB********************
```

which is completely the same as the case with --disable-release-vars.

Note that the benchmark itself looks correct because if you capture the variable storing large objects then the GC doesn't release objects as expected. See the following patch and report.

```patch
diff --git a/node_example/memory-usage-with-closures.jsx b/node_example/memory-usage-with-closures.jsx
index 04281fe..7f7c72c 100644
--- a/node_example/memory-usage-with-closures.jsx
+++ b/node_example/memory-usage-with-closures.jsx
@@ -52,7 +52,7 @@ function tick() : void {

q.push(() -> {
console.log(now);
- //console.log(largeObjects); // capture large objects
+ console.log(largeObjects); // capture large objects
});

_Main.reportRSS();
```

then the result:

```
jsx --run --enable-release-vars node_example/memory-usage-with-closures.jsx
42 MiB**************
55 MiB*******************
63 MiB*********************
76 MiB**************************
90 MiB******************************
103 MiB***********************************
116 MiB***************************************
130 MiB********************************************
143 MiB************************************************
157 MiB*****************************************************
170 MiB*********************************************************
```