You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What's the difference? It is that Statment.prototype.freemem calls have disappeared (there's in fact only 1 occurrence of "freemem" in the minified version, and it's the defintion) hence, unless it's called manually, Statement memory is never freed, even on Database.prototype.close. Hence a memory leak.
This solution is pretty simple. For any given type or object, use dot-syntax or quoted strings exclusively. Don't mix the syntaxes, especially in reference to the same property.
Also, when possible, prefer to use dot-syntax, as it supports better checks and optimizations. Use quoted string property access only when you don't want Closure Compiler to do renaming, such as when the name comes from an outside source, like decoded JSON.
This PR can used for reproduction of the memory leak lana-k/sqliteviz#70. It's how I discovered the problem.
The text was updated successfully, but these errors were encountered:
Thank you very much for the bug report and the detailed analysis ! This is a good find.
The behavior of the closure compiler is quite surprising, I would have expected it to raise an error or not attempt minimization when it encounters a call to a method it doesn't know.
I think the fix is pretty simple: we need to declare the methods unquoted in order to be able to use them unquoted :
I can make a PR that removes --closure 1 from the Makefile. That's plus ~50KB to sql-wasm.js, which isn't a big deal in my opinion (e.g. to make a quick fix).
But I don't have an idea how to make changes in api.js robust against Closure compiler's code requirements, and I'm not interested to figure out.
If I take sql.js 1.5, say from CDNJS, and take https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.5.0/sql-wasm.js, and un-minify it, this particular part of
Statment
's prototype is interesting:Now if I take the same part of source code (same with compiled without
--closure 1
) it looks like this:What's the difference? It is that
Statment.prototype.freemem
calls have disappeared (there's in fact only 1 occurrence of "freemem" in the minified version, and it's the defintion) hence, unless it's called manually,Statement
memory is never freed, even onDatabase.prototype.close
. Hence a memory leak.It's likely related to unmet Closure compilers advanced optimisation code requirements (though I didn't check whether
emcc
actually uses the advanced mode) and probably inconsistent method naming inapi.js
.This PR can used for reproduction of the memory leak lana-k/sqliteviz#70. It's how I discovered the problem.
The text was updated successfully, but these errors were encountered: