467,877 Members | 1,149 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

Regular expression problems

Hello al

I am not sure where to post this, so I hope this is correct.

We have written a Visual Studio AddIn that relies heavily on regular
expressions, which are often executed thousands of times. When running, it
works successfully for a while, but the Windows Page File Usage gradually
increases, and eventually the application freezes. We have traced the
problem to the regular expressions, but the problem does not apply equally
to all expressions. For example, the expression "^([\s]*)('|REM(
|\t|\v))([\s\S]*)$" does not cause any problems, whereas the expression
"^((("(("")|[^"])*")|([\s\S]*?))*)(('([\s\S]*))|$)$" causes a severe memory
leak. We always execute the expressions in 'interpreted' mode. Is there a
problem with certain expression constructs?

Thanks for any help/tips

Saira

Jul 21 '05 #1
  • viewed: 1249
Share:
1 Reply
"Saira" <Saira@[NoSpam]BayonetVentures.com> wrote in
news:e5**************@TK2MSFTNGP09.phx.gbl...
Hello al

I am not sure where to post this, so I hope this is correct.

We have written a Visual Studio AddIn that relies heavily on regular
expressions, which are often executed thousands of times. When running, it
works successfully for a while, but the Windows Page File Usage gradually
increases, and eventually the application freezes. We have traced the
problem to the regular expressions, but the problem does not apply equally
to all expressions. For example, the expression "^([\s]*)('|REM(
|\t|\v))([\s\S]*)$" does not cause any problems, whereas the expression
"^((("(("")|[^"])*")|([\s\S]*?))*)(('([\s\S]*))|$)$" causes a severe
memory leak. We always execute the expressions in 'interpreted' mode. Is
there a problem with certain expression constructs?


I don't know where your memory leak is, but I can tell you for sure that
this expression is burning CPU power and memory. Try it out with pen&pencil
on a 5 or 10-character string! It's O(n^2), and it stores every single match
(remember that MS RegEx's also store intermediate captures!). Also, what's
[\s\S] good for? Wouldn't '.' do the same?

What are you doing with the Match object the RegEx returns? It should be
quite big. I've tried it in Expresso on a medium-sized code file, took about
40 MB of memory - But everything seemd to be properly freed up when the GC
kicked in.

Can you create a small sample that shows the behaviour you've described
(memory leak not cleaned up by the GC)?

Niki
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Andrew Gaskell | last post: by
5 posts views Thread by Bradley Plett | last post: by
4 posts views Thread by Neri | last post: by
18 posts views Thread by Q. John Chen | last post: by
1 post views Thread by Saira | last post: by
2 posts views Thread by Brian Kitt | last post: by
7 posts views Thread by Billa | last post: by
25 posts views Thread by Mike | last post: by
1 post views Thread by Shawn B. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.