本文整理匯總了VB.NET中System.GC.WaitForPendingFinalizers方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET GC.WaitForPendingFinalizers方法的具體用法?VB.NET GC.WaitForPendingFinalizers怎麽用?VB.NET GC.WaitForPendingFinalizers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.GC
的用法示例。
在下文中一共展示了GC.WaitForPendingFinalizers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
Namespace WaitForPendingFinalizersExample
Class MyWaitForPendingFinalizersClass
' You can increase this number to fill up more memory.
Private Const numMfos As Integer = 1000
' You can increase this number to cause more
' post-finalization work to be done.
Private Const maxIterations As Integer = 100
Overloads Shared Sub Main()
Dim mfo As MyFinalizeObject = Nothing
' Create and release a large number of objects
' that require finalization.
Dim j As Integer
For j = 0 To numMfos - 1
mfo = New MyFinalizeObject()
Next j
'Release the last object created in the loop.
mfo = Nothing
'Force garbage collection.
GC.Collect()
' Wait for all finalizers to complete before continuing.
' Without this call to GC.WaitForPendingFinalizers,
' the worker loop below might execute at the same time
' as the finalizers.
' With this call, the worker loop executes only after
' all finalizers have been called.
GC.WaitForPendingFinalizers()
' Worker loop to perform post-finalization code.
Dim i As Integer
For i = 0 To maxIterations - 1
Console.WriteLine("Doing some post-finalize work")
Next i
End Sub
End Class
Class MyFinalizeObject
' Make this number very large to cause the finalizer to
' do more work.
Private maxIterations As Integer = 10000
Protected Overrides Sub Finalize()
Console.WriteLine("Finalizing a MyFinalizeObject")
' Do some work.
Dim i As Integer
For i = 0 To maxIterations - 1
' This method performs no operation on i, but prevents
' the JIT compiler from optimizing away the code inside
' the loop.
GC.KeepAlive(i)
Next i
MyBase.Finalize()
End Sub
End Class
End Namespace
示例2: GC.WaitForPendingFinalizers()
' 導入命名空間
Imports System
Imports System.Text
Imports System.Text.RegularExpressions
Public Class MainClass
Shared Sub Main( )
Dim myObject As Object = New Object()
Dim i As Integer
For i = 0 To 3
Console.WriteLine(String.Format("Generation = {0}", _
GC.GetGeneration(myObject)))
GC.Collect()
GC.WaitForPendingFinalizers()
Next i
End Sub 'Main
End Class