Closed Bug 218440 Opened 21 years ago Closed 21 years ago

Compiled scripts should not contain references to scope

Categories

(Rhino Graveyard :: Core, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: igor, Assigned: norrisboyd)

Details

Attachments

(4 files)

Currently in Rhino a Script object generated by the the interpreter contain a
reference to scope object as long as there is at least one regular expression
present in the script. It prevents the original scope from garbage collection if
script is executed against a new scope and can wrong references to be used when
using regular expressions. 

The optimizer does not have this problem since it creates regexp objects during
script execution.
One way to fix the problem is to implement the optimizer logic in the
interpreter as well when regular expression is compiled when a function is
created or when a script is executed. But it would mean that regexps are
recompiled each time script is executed. 

A better way would be to have an option to create scope-independent compiled
regexp presentation and then wrap it into a Scriptable when a function is
created and this is what the patch addresses. It splits newRegExp from
RegExpProxy into compileRegExp and wrapRegExp where compileRegExp creates a
self-contained object that does not have any references to scope and wrapRegExp
generates a Scriptable wrap for it.
The patch is an extension of the previous fix which dresses compiled regexps
into Scriptable clothes only during script execution and function construction
so InterpretedScript has no reference to scope.
Since compiled regexps is self-contained object, storing them as static fields
in a generated class would not cause any memory leaks even if the generated
classes are produced by JS compiler and used as a part of an application. 

This patch extends the previous one to include this optimization as well so
regexp literals are compiled only once while their Scriptable wrappers are
generated during function construction or script execution.
I committed the fix
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: