CreateMeasurementGraphics内存泄漏 [英] CreateMeasurementGraphics memory leak
问题描述
嗨。
请有人请告诉我如何正确处理
CreateMeasurementGraphics引用以阻止内存泄漏
以下代码:
对于x = 1到10000
Dim PrintDocument As New Printing.PrintDocument
Dim g As Graphics =
PrintDocument.PrinterSettings.CreateMeasurementGra phics
Dim hdc As IntPtr = g.GetHdc()
g.ReleaseHdc(hdc)
g.Dispose()
PrintDocument.Dispose()
下一页
非常感谢您的帮助。 />
Dave
Hi.
Could someone please tell me how I should correctly dispose of the
CreateMeasurementGraphics reference to stop the memory leak in the
following code:
For x = 1 To 10000
Dim PrintDocument As New Printing.PrintDocument
Dim g As Graphics =
PrintDocument.PrinterSettings.CreateMeasurementGra phics
Dim hdc As IntPtr = g.GetHdc()
g.ReleaseHdc(hdc)
g.Dispose()
PrintDocument.Dispose()
Next
Your help in much appreciated.
Dave
推荐答案
嗨Dave,
你确定吗它是一个memoryleak,dispose没有释放内存,它设置了一个状态的对象,垃圾收集器知道它可以设置
免费。
http://支持.mic rosoft.com/default...b;en-us;317866
您看过这个了吗?
Cor
Hi Dave,
Are you sure it is a memoryleak, the dispose does not free memory, it set
the object in a state that the the Garbage Collector knows that it can set
free.
http://support.microsoft.com/default...b;en-us;317866
Did you have a look at that?
Cor
嗨Dave,
你确定它是一个内存泄漏,dispose没有释放内存,它设置
垃圾收集器知道它可以设置
免费的状态中的对象。
http://support.microsoft.com/default...b;en-us; 317866
您有没看过这个?
Cor
Hi Dave,
Are you sure it is a memoryleak, the dispose does not free memory, it set
the object in a state that the the Garbage Collector knows that it can set
free.
http://support.microsoft.com/default...b;en-us;317866
Did you have a look at that?
Cor
" Cor Ligthert" <无********** @ planet.nl> schrieb
"Cor Ligthert" <no**********@planet.nl> schrieb
嗨Dave,
你确定它是一个内存泄漏,dispose没有释放内存,它将对象设置为垃圾状态收藏家知道它可以免费设置。
http://support.microsoft.com/default...b;en-us;317866
你看过那个吗? ?
Hi Dave,
Are you sure it is a memoryleak, the dispose does not free memory, it
set the object in a state that the the Garbage Collector knows that
it can set free.
http://support.microsoft.com/default...b;en-us;317866
Did you have a look at that?
我没有按照链接,但你写的是错的。如果它是对象分配的非托管资源类型之一,则可以释放内存
内存。
Dispose也不释放该对象可用于GC。配置
与GC无关。至少只要对象上还有一个引用,即使你调用了Dispose,对象也不会被收集。
-
Armin
I did not follow the link, but what you wrote is wrong. Dispose can free
memory if it''s one of the types of unmanaged resources the object allocated.
Dispose also does not free the object to be available for the GC. Dispose
has Nothing to do with GC. At least as long as there''s still a reference on
the object, the object won''t be collected, even if you called Dispose.
--
Armin
这篇关于CreateMeasurementGraphics内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!