Take the 2-minute tour ×

I've noticed that Matrix, GraphicsPath and Region classes implement IDisposable. From what I understand, if a class implements this interface then calling Dispose is a requirement, but I don't get why these classes implement it. What system resources do these classes use that it is required to release them. In my project I have a number of custom shapes that need to be drawn and I was using these classes to store transforms and geometry information of these objects which I would them use for things not always related to drawing (like hit testing and object arrangement management), but it seems I can't do so, since they use resources, and having a bunch of these objects might slow down entire system. Could someone comment on this? Perhaps I'm wrong in my assumptions and these objects are not required to be disposed after all?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

GDI+ uses unmanaged resources, by calling dispose those resources are released and can be reused by the system. By not calling dispose you are locking memory until the GC handles it.

share|improve this answer
add comment

Using a tool like Reflector or ILSpy you can investigate the dispose methods for yourself. I checked the Matrix case, it does release some native references in the Dispose(bool) method.

share|improve this answer
add comment

Your Answer


