GDI+ (GdiPlus) and ASP.NET

So we occasionally see customers that are either using System.Drawing themselves in their ASP.NET application or are using controls (like charting controls) that use it.

Under most circumstances, this works just fine.  But there are times where it does not, and this is cautioned to users on the System.Drawing page on MSDN.

We recently had a case where GDI+ was causing memory to jump up very quickly.  Looking at the heaps in DebugDiag showed us:

GDI-2

This shows the GdiPlus heap being very fragmented.  And looking at the crt heap, where GDI will allocate things:

GDI-1

If you look at the full picture, you will see that there is an allocation size of 2,691,448 which is taking up 782.86 MB.

There is a very good description of this on:
Charting in ASP.NET (alas: DGI+ not supported in a service)

Note that there are also sites which talk about using System.Drawing on ASP.NET, for example:
https://www.geekpedia.com/tutorial123_Working-with-GDIplus-in-ASP.NET.html

While this code will work, I would caution that if you run into problems, don't be surprised if this is what is causing the problem, especially if it gets heavy use on your site.

kick it on DotNetKicks.com