1

I've been over this for a couple of time and can't figure it out. the method DrawPath is throwing a System.OutOfMemoryException.

I've seen that the pen.DashPattern is actually throwing System.OutOfMemoryException as well, so I set the dash pattern, but correcting that didn't prevent the error.

using (var pen = new Pen(Color.Black,1.0f))
{
    pen.DashPattern = new[]{1.0f};
    pen.Transform = context.ReverseTransform;
    try
    {
        using (var temporaryPath = new GraphicsPath(path.PathPoints, path.PathTypes))
        {
            context.Graphics.DrawPath(pen, temporaryPath);
        }
    }
}

Any help in here would be lovely! thanks in advance!

Diogo
  • 316
  • 5
  • 11
  • how big is your path.PathPoints array? – Tigran Aug 30 '11 at 18:38
  • PathPoints vary between 0 and a couple hundred... – Diogo Aug 30 '11 at 18:47
  • Seeing the code and your responce I would say that the real problem is not here. Can use some memory profiler like Ed suggests, or just http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx useProcessExploer. Run your program and work with it, and contemporary looking on WorkingSet visible in Process Explorer figure out the UX path to the trouble. if you're on 32 bit machine, if working set arrives arrounf 1.2GB of mem space process will lead to memoverflow exception. – Tigran Aug 30 '11 at 18:49

1 Answers1

1

It's highly unlikely that this is the root cause of your problem considering that you are property disposing of the Pen and Path object.. That line may be throwing the exception, but the problem has already been brewing for some time and this is just the straw that broke the camel's back, tipped the iceberg... you get it. That said, it would be helpful to know how large your PathPoints array is as Tigran mentioned in a comment.

Get yourself a good profiler (I use RedGate's ANTS Memory Profiler which has a free trial), put your app through it's paces, let the memory usage build up, and then use the profiler results to narrow down the actual culprit. Come back with some more info or your results and I will be happy to help further.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
  • thanks for your reply. I have that program but didn't give it a try yet. this piece of code is running in a separate thread, and oddly enough it doesn't crash the thread or the main application. I could just ignore the exception and the program would be fine, but it doesn't seem like a good policy... I know there must be some mistake somewhere. I'll give the ANTS program a try though! – Diogo Aug 30 '11 at 18:48
  • You may be able to ignore it running under VS, but in production it will crash. Even if you do ignore it it leaves your program in a bad state. Use the profiler, it will save you a lot of time. – Ed S. Aug 30 '11 at 18:51