[Mono-list] question about regular expressions in Mono on Windows

Tomar tomar@apricot.com
01 Aug 2004 01:56:57 -0500

Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Are you sure its a memory leak?  Since its managed memory, unless you
specifically dispose of objects or do some of the System.GC stuff or
give it a good reason too (like push memory usage to the limit) the
virtual machine has little reason to reclaim any memory.  Its an
"expensive" operation to walk the objects constantly looking for things
to release.  I'm not saying that the Regex object is error free or can't
be improved but allocating memory isn't out of the ordinary.

Just out of curiosity have you tried using "csc" and MS's .Net Framework
1.1 to see if it eats as much?

Tom Larsen

On Sat, 2004-07-31 at 08:35, Davy Brion wrote:
> about six weeks ago, i thought i found a memory leak in the Regular
> Expressions part of Mono, and i mailed a testcase to the mono list but
> Gonzalo said the problem didn't occur when he tried it.  This was around
> the mono 1.0 beta2 timeframe iirc.
> On Linux, i don't have that problem anymore, but i've recently managed
> to get my application working on Windows (with GTK#) but unfortunately
> it is leaking a lot of memory on Windows.  I've tracked it down and it
> turns out that it's because my application uses regular expressions on
> strings a lot.  with a lot i mean like almost continiously actually.
> If i comment out the line of code that checks for the regular
> expression, the memory usage is normal.  If i let it execute the
> regular expression, and comment out the stuff that should be executed
> after that, i can already see the memory usage going up.  This only
> happens on Windows, not on Linux.
> I've tried a lot of stuff to work around this problem, but i'm getting
> pretty desperate to be honest.  I really have no clue what else i can
> try to avoid this problem.
> the following testcase illustrates the problem on Windows:
> using System;
> using System.Text;
> using System.Text.RegularExpressions;
> using System.Threading;
> class MainClass
> {
>        public static void Main(string[] args)
>        {
>                Match match;
>                string strPattern =3D @"\w \w \w \w \w: \d";
>                for (long i=3D0;i<50000;i++)
>                {
>                        string strTest =3D "This is a simple test: " +
> i.ToString() ;
>                        match =3D Regex.Match(strTest,strPattern);
>                        Console.WriteLine(i);
>                        Thread.Sleep(10);
>                }
>        }
> }
> if i run that on windows, and i watch the memory usage in the Task
> Manager, the memory just keeps going up.  The longer it runs, the more
> memory it uses.
> i'm using the combined mono/gtk# installer for windows if that makes
> any difference.
> thanks
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
Tomar <tomar@apricot.com>

Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

Version: GnuPG v1.0.7 (GNU/Linux)