BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object

The methods in this class influence when garbage collection is performed on an object and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the age category, or generation, of memory allocated to an object.

The garbage collector tracks and reclaims objects allocated in managed memory. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. Alternatively, an application can force garbage collection using the method.

Garbage collection consists of the following steps:

The garbage collector searches for managed objects that are referenced in managed code.

The garbage collector tries to finalize objects that are not referenced.

The garbage collector frees objects that are not referenced and reclaims their memory.

During a collection, the garbage collector will not free an object if it finds one or more references to the object in managed code. However, the garbage collector does not recognize references to an object from unmanaged code, and might free objects that are being used exclusively in unmanaged code unless explicitly prevented from doing so. The method provides a mechanism that prevents the garbage collector from collecting objects that are still in use in unmanaged code.

Aside from managed memory allocations, implementations of the garbage collector do not maintain information about resources held by an object, such as file handles or database connections. When a type uses unmanaged resources that must be released before instances of the type are reclaimed, the type can implement a finalizer.

In most cases, finalizers are implemented by overriding the method; however, types written in C# or C++ implement destructors, which compilers turn into an override of . In most cases, if an object has a finalizer, the garbage collector calls it prior to freeing the object. However, the garbage collector is not required to call finalizers in all situations; for example, the method explicitly prevents a finalizer from being called. Also, the garbage collector is not required to use a specific thread to finalize objects, or guarantee the order in which finalizers are called for objects that reference each other but are otherwise available for garbage collection.

In scenarios where resources must be released at a specific time, classes can implement the interface, which contains the method that performs resource management and cleanup tasks. Classes that implement must specify, as part of their class contract, if and when class consumers call the method to clean up the object. The garbage collector does not, by default, call the method; however, implementations of the method can call methods in the class to customize the finalization behavior of the garbage collector.

It is recommended, but not required, that garbage collectors support object aging using generations. A generation is a unit of measure of the relative age of objects in memory. The generation number, or age, of an object indicates the generation to which an object belongs. Objects created more recently are part of newer generations, and have lower generation numbers than objects created earlier in the application life cycle. Objects in the most recent generation are in generation 0.

Controls the system garbage collector, a service that automatically reclaims unused memory.

- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  In determining when to schedule garbage collection, the runtime takes into account how much managed memory is allocated. If a small managed object allocates a large amount of unmanaged memory, the runtime takes into account only the managed memory, and thus underestimates the urgency of scheduling garbage collection. The method informs the runtime of this additional pressure on system memory.

  In the simplest usage pattern, a managed object allocates unmanaged memory in the constructor and releases it in the Dispose or Finalize method. Call the method after allocating the unmanaged memory, and call the method after releasing it.

  In more complicated scenarios, where the unmanaged memory allocation changes substantially during the lifetime of the managed object, you can call the and methods to communicate these incremental changes to the runtime.

  You must ensure that you remove exactly the amount of pressure you add. Failing to do so can adversely affect the performance of the system in applications that run for long periods of time.

  Informs the runtime of a large allocation of unmanaged memory that should be taken into account when scheduling garbage collection.

  The incremental amount of unmanaged memory that has been allocated.
- Method
  4.0.0.0
  System.Void

  This method cancels a garbage collection notification that was registered by using the method. You do not have to call this method before adjusting threshold parameter values in subsequent calls to the method.

  Cancels the registration of a garbage collection notification.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  Use this method to try to reclaim all memory that is inaccessible. It performs a blocking garbage collection of all generations.

  All objects, regardless of how long they have been in memory, are considered for collection; however, objects that are referenced in managed code are not collected. Use this method to force the system to try to reclaim the maximum amount of available memory.

  Starting with the net_v451, you can compact the large object heap (LOH) by setting the property to before calling the method, as the following example illustrates.

  code reference: System.Runtime.GCSettings#1

  Forces an immediate garbage collection of all generations.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  Use this method to try to reclaim memory that is inaccessible. However, using this method does not guarantee that all inaccessible memory in the specified generation is reclaimed.

  If object aging is implemented, the garbage collector does not collect objects with a generation number that is higher than the specified generation. If object aging is not implemented, the garbage collector considers all objects during the garbage collection.

  Use the property to determine the maximum valid value of the parameter.

  To have the garbage collector consider all objects regardless of their generation, use the version of this method that takes no parameters. To have the garbage collector reclaim objects based on a setting, use the method overload.

  Forces an immediate garbage collection from generation 0 through a specified generation.

  The number of the oldest generation that garbage collection can be performed on.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  Use the parameter to specify whether garbage collection should occur immediately or only if the time is optimal to reclaim objects. Using this method does not guarantee that all inaccessible memory in the specified generation is reclaimed.

  To adjust the intrusiveness of garbage collection during critical periods in your application, set the property.

  The garbage collector does not collect objects with a generation number higher than specified by the parameter. Use the property to determine the maximum valid value of .

  To have the garbage collector consider all objects regardless of their generation, use the version of this method that takes no parameters.

  To have the garbage collector reclaim objects up to a specified generation of objects, use the method overload. When you specify the maximum generation, all objects are collected.

  Forces a garbage collection from generation 0 through a specified generation, at a time specified by a value.

  The number of the oldest generation that garbage collection can be performed on. One of the enumeration values that specifies the behavior for the garbage collection.
- Method
  4.0.0.0
  System.Void `` `` ``

  The following table summarizes the interaction of the and parameters:

  is true

  is false

  or

  A blocking collection is performed as soon as possible. If a background collection is in progress and is 0 or 1, the method immediately triggers a blocking collection and returns when the collection is finished. If a background collection is in progress and is 2, the method waits until the background collection is finished, triggers a blocking generation 2 collection, and then returns.

  A collection is performed as soon as possible. The method requests a background collection, but this is not guaranteed; depending on the circumstances, a blocking collection may still be performed. If a background collection is already in progress, the method returns immediately.

  A blocking collection may be performed, depending on the state of the garbage collector and the parameter. The garbage collector tries to provide optimal performance.

  A collection may be performed, depending on the state of the garbage collector. The method requests a background collection, but this is not guaranteed; depending on the circumstances, a blocking collection may still be performed. The garbage collector tries to provide optimal performance. If a background collection is already in progress, the method returns immediately.

  If a call to the method performs a full blocking garbage collection, you can also compact the large object heap by setting the property to before calling the method.

  Forces a garbage collection from generation 0 through a specified generation, at a time specified by a value, with a value specifying whether the collection should be blocking.

  The number of the oldest generation that garbage collection can be performed on. One of the enumeration values that specifies whether the garbage collection is forced ( or ) or optimized (). true to perform a blocking garbage collection; false to perform a background garbage collection where possible.
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Int32 ``

  If you implement your own resource management, you might need to force garbage collection periodically by calling the method. Because this is an expensive operation, you can improve performance by skipping the call when a garbage collection has occurred recently. Save the value returned by immediately after calling . The next time you need to call , compare the current value returned by to the saved value. If the two values are equal, no collection has occurred in the interim and it is reasonable to call again.

  Returns the number of times garbage collection has occurred for the specified generation of objects.

  The number of times garbage collection has occurred for the specified generation since the process was started.

  The generation of objects for which the garbage collection count is to be determined.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 ``

  Use this method to determine the age of an object, and then use that information with the method to force the garbage collector to collect objects in the same generation. For example, use this method when you have a set of objects that are created as a group and that become inaccessible at the same time.

  Returns the current generation number of the specified object.

  The current generation number of .

  The object that generation information is retrieved for.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` To be added.

  Returns the current generation number of the target of a specified weak reference.

  The current generation number of the target of .

  A that refers to the target object whose generation number is to be determined.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64 ``

  If the parameter is true, this method waits a short interval before returning while the system collects garbage and finalizes objects. The duration of the interval is an internally specified limit determined by the number of garbage collection cycles completed and the change in the amount of memory recovered between cycles. The garbage collector does not guarantee that all inaccessible memory is collected.

  Retrieves the number of bytes currently thought to be allocated. A parameter indicates whether this method can wait a short interval before returning, to allow the system to collect garbage and finalize objects.

  A number that is the best available approximation of the number of bytes currently allocated in managed memory.

  true to indicate that this method can wait for garbage collection to occur before returning; otherwise, false.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void ``

  The purpose of the method is to ensure the existence of a reference to an object that is at risk of being prematurely reclaimed by the garbage collector. A common scenario where this might happen is when there are no references to the object in managed code or data, but the object is still in use in unmanaged code such as Win32 APIs, unmanaged DLLs, or methods using COM.

  This method references the parameter, making that object ineligible for garbage collection from the start of the routine to the point, in execution order, where this method is called. Code this method at the end, not the beginning, of the range of instructions where must be available.

  The method performs no operation and produces no side effects other than extending the lifetime of the object passed in as a parameter.

  References the specified object, which makes it ineligible for garbage collection from the start of the current routine to the point where this method is called.

  The object to reference. 0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 To be added.

  The generation number, or age, of an object is an implementation-defined relative measure of an object's lifespan. The most recently created objects are in generation 0 and the oldest objects are in a generation less than or equal to the generation returned by the property.

  The garbage collector assumes that newer memory is more likely to be eligible for garbage collection than older memory. Therefore, the garbage collector improves its performance by adjusting generation numbers each time it reclaims memory, and the property value can grow over time.

  If object aging is implemented, the property returns the maximum generation number used by the system; otherwise, this property returns zero.

  Gets the maximum number of generations that the system currently supports.

- Method
  4.0.0.0
  System.Void `` ``

  If you have situations in which a full garbage collection by the common language runtime would adversely affect your application's performance, you can determine whether the runtime is about to induce a full garbage collection and circumvent that collection by inducing a collection yourself (using the method) when conditions are still favorable. For more information about what represents a full garbage collection, see Garbage Collection Notifications.

  When you register for a garbage collection notification, you can determine whether the event that signals an approaching full garbage collection has been raised by checking the status of the garbage collection notification. This pattern resembles how the operating system monitors for low memory notifications.

  Use the following guidelines for specifying the and parameters:

  The larger the threshold value, the further away in time the collection will likely occur and the sooner the notification will be raised.

  A larger threshold value provides more opportunities for the runtime to check for an approaching collection. This increases the likelihood that you will be notified. However, you should not set the threshold too high because that results in a longer wait before the runtime induces the next collection.

  When you induce a collection yourself upon notification using a high threshold value, more objects are reclaimed than would be reclaimed by the runtime's next collection.

  The smaller the threshold value, the greater the likelihood that a collection will occur sooner and the notification will be raised later.

  Specifies that a garbage collection notification should be raised when conditions favor full garbage collection and when the collection has been completed.

  A number between 1 and 99 that specifies when the notification should be raised based on the objects surviving in generation 2. A number between 1 and 99 that specifies when the notification should be raised based on objects allocated in the large object heap.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  In determining when to schedule garbage collection, the runtime takes into account how much managed memory is allocated. If a small managed object allocates a large amount of unmanaged memory, the runtime takes into account only the managed memory, and thus underestimates the urgency of scheduling garbage collection. The method informs the runtime of this additional pressure on system memory, and the method informs the runtime that the additional pressure has been released.

  In the simplest usage pattern, a managed object allocates unmanaged memory in the constructor and releases it in the Dispose or Finalize method. Call the method after allocating the unmanaged memory, and call the method after releasing it.

  In more complicated scenarios, where the unmanaged memory allocation changes substantially during the lifetime of the managed object, you can call the and methods to communicate these incremental changes to the runtime.

  You must ensure that you remove exactly the amount of pressure you add. Failing to do so can adversely affect the performance of the system in applications that run for long periods of time.

  Informs the runtime that unmanaged memory has been released and no longer needs to be taken into account when scheduling garbage collection.

  The amount of unmanaged memory that has been released.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` is a reference. The caller of this method is not the same as the object passed to this method.

  The method adds the parameter to the list of objects that request finalization before the garbage collector frees the object. The parameter must be the caller of this method.

  Calling the method does not guarantee that the garbage collector will call an object's finalizer.

  By default, all objects that implement finalizers are added to the list of objects that require finalization; however, an object might have already been finalized or might have disabled finalization by calling the method.

  A finalizer can use this method to resurrect itself or an object that it references.

  Requests that the system call the finalizer for the specified object for which has previously been called.

  The object that a finalizer must be called for. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void `` is a reference. The caller of this method is not the same as the object passed to this method.

  This method sets a bit in the object header of , which the runtime checks when calling finalizers. A finalizer, which is represented by the method, is used to release unmanaged resources before an object is garbage-collected. If does not have a finalizer, the call to the method has no effect.

  Objects that implement the interface can call this method from the object's implementation to prevent the garbage collector from calling on an object that does not require it. Typically, this is done to prevent the finalizer from releasing unmanaged resources that have already been freed by the implementation.

  Requests that the common language runtime not call the finalizer for the specified object.

  The object whose finalizer must not be executed. 0
- Method
  4.0.0.0
  System.GCNotificationStatus

  Use the enumeration returned by this method to determine the status of the current garbage collection notification that was registered by using the method. You can also use the method to determine whether the full garbage collection has completed.

  When the enumeration returns , you can do tasks such as preventing additional objects from being allocated and inducing a collection yourself with the method. Note that the notification does not guarantee that a full garbage collection will occur, only that conditions have reached the threshold that are favorable for a full garbage collection to occur.

  This method waits indefinitely for a garbage collection notification to be obtained. If you want to specify a time-out period for the method to return if the notification cannot be obtained, use the method overload. If you call this method without specifying a time-out, you can call the method if you are waiting longer than preferred.

  You should follow this method with a call to the method to make sure that you have had a full garbage collection. Calling this method alone causes indeterminate results.

  Returns the status of a registered notification for determining whether a full, blocking garbage collection by the common language runtime is imminent.

  The status of the registered garbage collection notification.

- Method
  4.0.0.0
  System.GCNotificationStatus ``

  Use the enumeration returned by this method to determine the status of the current garbage collection notification that was registered by using the method. You can also use the method to determine whether the full garbage collection has completed.

  Note that this method returns immediately whenever a garbage collection notification status is obtained, regardless of the value specified by . If a garbage collection notification status is not obtained before times out, this method returns .

  When the enumeration returns , you can do tasks such as preventing additional objects from being allocated and inducing a collection yourself with the method. Note that the notification does not guarantee that a full garbage collection will occur, only that conditions have reached the threshold that are favorable for a full garbage collection to occur.

  You can call the method when you cannot wait for the time-out period to elapse.

  You should follow this method with a call to the method to make sure that you have had a full garbage collection. Calling this method alone causes indeterminate results.

  Returns, in a specified time-out period, the status of a registered notification for determining whether a full, blocking garbage collection by the common language runtime is imminent.

  The status of the registered garbage collection notification.

  The length of time to wait before a notification status can be obtained. Specify -1 to wait indefinitely.
- Method
  4.0.0.0
  System.GCNotificationStatus

  Use the enumeration returned by this method to determine the status of the current garbage collection notification that was registered by using the method. You can also use the method to determine whether a full garbage collection is imminent.

  When the enumeration returns , you can do tasks such as resuming work and obtaining a collection count with the property.

  This method waits indefinitely for a garbage collection notification to be obtained. If you want to specify a time-out period for the method to return if the notification cannot be obtained, use the method overload. If you call this method without specifying a time-out, you can call the method if you are waiting longer than preferred.

  This method call should be preceded with a call to the method to make sure that you have had a full garbage collection. Calling this method alone can produce indeterminate results.

  Returns the status of a registered notification for determining whether a full, blocking garbage collection by the common language runtime has completed.

  The status of the registered garbage collection notification.

- Method
  4.0.0.0
  System.GCNotificationStatus ``

  Use the enumeration returned by this method to determine the status of the current garbage collection notification that was registered by using the method. You can also use the method to determine whether a full garbage collection is imminent.

  Note that this method returns immediately whenever a garbage collection notification status is obtained, regardless of the value specified by . If a garbage collection notification status is not obtained before times out, this method returns .

  When the enumeration returns , you can do tasks such as resuming work and obtaining a collection count with the property.

  You can call the method when you cannot wait for the time-out period to elapse.

  This method call should be preceded with a call to the method to make sure that you have had a full garbage collection. Calling this method alone can produce indeterminate results.

  Returns, in a specified time-out period, the status of a registered notification for determining whether a full, blocking garbage collection by common language the runtime has completed.

  The status of the registered garbage collection notification.

  The length of time to wait before a notification status can be obtained. Specify -1 to wait indefinitely.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  When the garbage collector finds objects that can be reclaimed, it checks each object to determine the object's finalization requirements. If an object implements a finalizer and has not disabled finalization by calling , the object is placed in a list of objects that are marked as ready for finalization. The garbage collector calls the methods for the objects in this list and removes the entries from the list. This method blocks until all finalizers have run to completion.

  The thread on which finalizers are run is unspecified, so there is no guarantee that this method will terminate. However, this thread can be interrupted by another thread while the method is in progress. For example, you can start another thread that waits for a period of time and then interrupts this thread if this thread is still suspended.

  Suspends the current thread until the thread that is processing the queue of finalizers has emptied that queue.

  0
0