AddMemoryPressure( )
and
RemoveMemoryPressure( )
. These are used to
indicate that a large amount of unmanaged memory has been allocated or released by the
program. They are important because the memory management system has no oversight
on unmanaged memory. If a program allocates a large amount of unmanaged memory, then
performance might be affected because the system has no way of knowing that free memory
has been reduced. By calling
AddMemoryPressure( )
when allocating large amounts of
unmanaged memory, you let the CLR know that memory has been reduced. By calling
RemoveMemoryPressure( )
, you let the CLR know the memory has been freed. Remember:
RemoveMemoryPressure( )
must be called only to indicate that memory reported by a call
to
AddMemoryPressure( )
has been released.
Method
Meaning
public static void
AddMemor yPressure(long
size
)
Indicates that
size
number of bytes of unmanaged
memor y have been allocated.
public static void Collect( )
Initiates garbage collection.
public static void Collect(int
maxGen
)
Initiates garbage collection for memor y with generation
numbers of 0 through
maxGen.
public static void Collect(int
maxGen
,
GCCollectionMode
GCMode
)
Initiates garbage collection for memor y with generation
numbers of 0 through
maxGen
as specified by
GCMode
.
public static int CollectionCount(int
gen
)
Returns the number of garbage collections that have
taken place for memor y having the generation number
specified by
gen.
public static int GetGeneration(object
o
)
Returns the generation number for the memor y referred
to by
o.
public static int
GetGeneration(WeakReference
o
)
Returns the generation number for the memor y
referred to by the weak reference specified by
o.
A
weak reference does not prevent the object from being
garbage-collected.
public static long
GetTotalMemor y(bool
collect
)
Returns the total number of bytes currently allocated. If
collect
is true, garbage collection occurs first.
public static void KeepAlive(object
o
)
Creates a reference to
o,
thus preventing it from being
garbage collected. This reference ends when
KeepAlive( )
executes.
public static void
RemoveMemor yPressure(long
size
)
Indicates that
size
number of bytes of unmanaged
memor y have been released.
public static void
ReRegisterForFinalize(object
o
)
Causes the finalizer (i.e., the destructor) for
o
to be called.
This method undoes the effects of
SuppressFinalize( )
.
public static void
SuppressFinalize(object
o
)
Prevents the finalizer (i.e., the destructor) for
o
from
being called.
public static void
WaitForPendingFinalizers( )
Halts execution of the invoking thread until all pending
finalizers (i.e., destructors) have been called.
T
ABLE
21-15
Methods Defi ned by
GC
www.freepdf-books.com
Do'stlaringiz bilan baham: |