Reference.ReachabilityFence(Object) Method

Definition

Ensures that the object referenced by the given reference remains <em>strongly reachable</em>, regardless of any prior actions of the program that might otherwise cause the object to become unreachable; thus, the referenced object is not reclaimable by garbage collection at least until after the invocation of this method.

[Android.Runtime.Register("reachabilityFence", "(Ljava/lang/Object;)V", "", ApiSince=28)]
public static void ReachabilityFence (Java.Lang.Object? ref);
[<Android.Runtime.Register("reachabilityFence", "(Ljava/lang/Object;)V", "", ApiSince=28)>]
static member ReachabilityFence : Java.Lang.Object -> unit

Parameters

ref
Object

the reference. If null, this method has no effect.

Attributes

Remarks

Ensures that the object referenced by the given reference remains <em>strongly reachable</em>, regardless of any prior actions of the program that might otherwise cause the object to become unreachable; thus, the referenced object is not reclaimable by garbage collection at least until after the invocation of this method. Invocation of this method does not itself initiate garbage collection or finalization.

This method establishes an ordering for <em>strong reachability</em> with respect to garbage collection. It controls relations that are otherwise only implicit in a program -- the reachability conditions triggering garbage collection. This method is designed for use in uncommon situations of premature finalization where using synchronized blocks or methods, or using other synchronization facilities are not possible or do not provide the desired control. This method is applicable only when reclamation may have visible effects, which is possible for objects with finalizers (See Section 12.6 17 of The Java™ Language Specification) that are implemented in ways that rely on ordering control for correctness.

Added in 9.

Java documentation for java.lang.ref.Reference.reachabilityFence(java.lang.Object).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to