JScript Memory Leak

M

Mitch Freed

I have been using the JScript eval() method from C# to evaluate
conditional logic at run-time. I found that implementing a solution
similar to the example posted at:
http://www.odetocode.com/Code/80.aspx, seems to handle memory the most
efficiently. However, if executing in a tight loop (say, while(true){//
jscript eval}, JScript will leak memory and grow the virtual memory
until the performance of the machine has been degraded significantly. I
have noticed however that if I do not evaluate regular expressions the
JScript eval works wonderfully. If I eval a regex though (i.e.
/foo/.test('foobar')), the memory will leak as I described above. I
have searched and searched for any information about this and have not
been able to find anything. Should I be posting this to the JScript
group for this kind of information? Does anyone know why JScript leaks
memory like that (only under certain conditions)?

Thanks,
Mitch
 
N

Nicholas Paldino [.NET/C# MVP]

Mitch,

Why are you using eval to evaluate the regular expressions? Why not
just use the Regex class in the System.Text.RegularExpressions namespace?

Hope this helps.
 
M

Mitch Freed

Thanks for the reply Nicholas. What I'm using the eval for is to build
an statement piece by piece and then I eval it using the eval()
function. So by the time I'm done building the statement it could look
something like:

1 == 1 && /foo/i.text('foobar') && (1 != 2 || 'a' == 'b')

Right know I am trying to eval the expression as a whole, instead of
piece by piece -- makes it easier for me. I have actually been able to
work around the memory issues when using a regex in the eval(), but I
am really interested to know what causes the memory issues. I can give
an example piece of code that reproduces the memory problems if anyone
is interested.
 
N

Nicholas Paldino [.NET/C# MVP]

Mitch,

Well, where are you seeing the virtual memory grow? You aren't looking
at this in the task manager are you?

Also, while I see how useful this kind of dynamic evaluation can be, you
really should have more concrete implementations of the code path.

Not that it helps your current situation, but JScript goes through a lot
of hoops in order to provide eval, from what it seems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top