我可以在 .NET 中创建多少个位图?
.NET Bitmap 类使用 GDI+
我想知道我可以创建多少个位图。
创建太多Bitmap会导致内存泄漏吗?
.NET Bitmap class uses GDI+
I want to know how many Bitmaps I can create.
Will memory leak when create too many Bitmaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
每个会话的 GDI 句柄限制为 65536。请参阅 http://msdn.microsoft.com/en-我们/库/ms724291(VS.85).aspx
The limit of GDI handles is 65536 per session. See http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx
您可能会遇到内存泄漏问题,但您可以通过编写简单的代码来修复它
You will might be face memory leak problem but you can fix it by writing simple code
位图是一个 GDI+ 对象,您在系统中获得的此类对象数量有限。当然你可以调整系统。我不认为你会遇到内存泄漏,但如果超过该限制,则会出现系统异常。
Bitmap is a GDI+ object and you get limited number of those object in your system. Of course you may adjust the system. I don't think you will get memory leak but a system exception in case you exceed that limit.
Windows XP 和 Vista - 默认限制
Windows XP 和 Vista 中的默认限制为 10,000。 监控应用程序拥有的 GDI 对象数量
您可以从“任务管理器” http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx
注意:我用 HashMorePages = True 测试了 PrintPreview,直到它抛出异常(大约 4800 页) ),每个Page需要2个Gdi+对象。
Windows XP and Vista - default limit
The default limit in Windows XP and Vista is 10,000. You can monitor the number of GDI objects an application has from the "task manager"
http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx
Note: I tested a PrintPreview with HashMorePages = True until It Throw Exception (about 4800 pages), Each Page needs 2 Gdi+ objects.
MSDN 说
来源:http://msdn.microsoft.com/ en-us/library/ms724291%28VS.85%29.aspx
MSDN says
Source: http://msdn.microsoft.com/en-us/library/ms724291%28VS.85%29.aspx
只要使用框架来制作,内存就不会泄漏。 Bitmap 类的制作方式是实例在最终确定时自行处置,就像任何有自尊的 IDisposable 所做的那样,因此即使忘记处置它也不会导致问题。
至于你能做多少,这取决于你有多少内存。
Memory won't leak as long as you use the framework to make them. The Bitmap class is made in such a way that instances dispose themselves when finalized, as any self-respecting IDisposable does, so even forgetting to Dispose it won't cause issues.
As for how many you can make, that depends on how much memory you have to work with.