GDI+ Region、Matrix 和 GraphicsPath 处理

发布于 2024-11-10 04:23:02 字数 288 浏览 5 评论 0原文

我注意到 Matrix、GraphicsPath 和 Region 类实现了 IDisposable。据我了解,如果一个类实现了这个接口,那么调用 Dispose 是一个要求,但我不明白为什么这些类实现它。这些类使用了哪些系统资源,需要释放它们。在我的项目中,我有许多需要绘制的自定义形状,我使用这些类来存储这些对象的变换和几何信息,我将它们用于并不总是与绘图相关的事情(例如命中测试和对象排列管理) ),但似乎我不能这样做,因为它们使用资源,并且拥有一堆这些对象可能会减慢整个系统的速度。有人可以对此发表评论吗?也许我的假设是错误的,这些对象毕竟不需要被处理?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-11-17 04:23:02

使用 Reflector 或 ILSpy 等工具,您可以自己研究处置方法。我检查了 Matrix 案例,它确实在 Dispose(bool) 方法中释放了一些本机引用。

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.

丶情人眼里出诗心の 2024-11-17 04:23:02

GDI+使用非托管资源,通过调用dispose这些资源被释放并可以被系统重用。通过不调用 dispose,您将锁定内存,直到 GC 处理它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文