开发者

GDI+ Region, Matrix and GraphicsPath disposal

开发者 https://www.devze.com 2023-03-09 10:15 出处:网络
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 w

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 u开发者_运维知识库se 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消