1

I'm using DashStyle.Dash while rendering my hierarchy of objects. My application uses Graphics.Transform extensively and I find that at some scale values (including a scale of 100%) and some angles of rotation, Graphics.DrawLine throws OutOfMemoryException when using a pen with DashStyle.Dash. Using Google I found that this is a well-known problem. Microsoft tells us that this is not a blocking issue. So far, I have not found a workaround for this problem.

What are my options?

4
  • 1
    I assume you're Disposing of the Pen? And one of the articles mentioned said to avoid duplicate points in Graphics.DrawLines. You are using the singular version, correct? You might post some code; maybe that will help get some answers. Commented Aug 14, 2009 at 19:43
  • You definitely have to Dispose all your GDI+ objects. I have had many problems when I didn't, and one of them was an Out of Memory exception. Commented Aug 24, 2009 at 20:12
  • Another idea is to take a profiler and see what's may be going on with the code, if it's a memory leak for example, and help you to solve it. Commented Aug 24, 2009 at 20:13
  • I am of the opinion that the memory in question here is that of the graphics card. And I think the problem is that I was caching pens between WM_PAINT events which some have mentioned as a bad idea. Commented Aug 25, 2009 at 7:27

1 Answer 1

1

I just encountered the same issue. Upon further investigation I discovered the following.

  1. The line length was exactly the custom dash pattern length. Changing the line length +/- 1 pixel avoided the error.
  2. I was using LineCapRound and DashCapRound, switching to LineCapSquare and DashCapFlat avoided the error
  3. The error came from trying flatten the path (presumably from the rounded ends)
  4. The pen width was zero.

My final solution was to not draw zero width lines!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.