J
James Sadlier
I'm writing a windows service, that does some stuff every second in a loop,
generating random numbers. It works fine apart from the fact that for some
reason it's using an extra 8K of memory every loop. I've isolated it down to
the use of the Random object. When I remove the use of this object my
service's memory usage stays static.
Any idea what's going wrong? Random doesn't implement IDisposable, so I
can't call Finalize() or Dispose() on it. Nullifying the object doesn't seem
to be cleaning it up, and I don't want to go calling GC.Collect() all the
time.
The code basically looks like this:
while(true)
{
DoStuff();
Thread.Sleep(1000);
}
....
private void DoStuff()
{
//if I remove the next two lines the problem goes away
Random myRandomObject = new Random(DateTime.Now.Millisecond);
myRandomObject = null;
/* some other work*/
}
Any thoughts?
generating random numbers. It works fine apart from the fact that for some
reason it's using an extra 8K of memory every loop. I've isolated it down to
the use of the Random object. When I remove the use of this object my
service's memory usage stays static.
Any idea what's going wrong? Random doesn't implement IDisposable, so I
can't call Finalize() or Dispose() on it. Nullifying the object doesn't seem
to be cleaning it up, and I don't want to go calling GC.Collect() all the
time.
The code basically looks like this:
while(true)
{
DoStuff();
Thread.Sleep(1000);
}
....
private void DoStuff()
{
//if I remove the next two lines the problem goes away
Random myRandomObject = new Random(DateTime.Now.Millisecond);
myRandomObject = null;
/* some other work*/
}
Any thoughts?