Click or drag to resize

JVMBridgeCoreDisposable Class

Helper class to add IDisposable behavior on classes based on JVMBridgeCore. This class has two different usages:
  • Using the Dispose method, the class invokes close method on JVM object and immediately release the reference. JVMBridgeCore lost the possibility to immediately release the JVM reference and the JVM object shall wait the .NET Garbage Collector
  • In some operating conditions, mainly under heavy GC pressure, the CLR can retires the underlying object (as explained in previous point); With JVMBridgeBase classes it is possible to use the IDisposable pattern to avoid early reference retirement. With JVMBridgeCore based classes the previous pattern cannot be applied and something like the following shall be used to avoid the invocation of the finalizer:
    C#
    class TheClass : JVMBridgeCore<TheClass>
    {
        public override string BridgeClassName => "org.company.TheClass";
    
        public TheClass()
        {
        }
    }
    
    var cls = new TheClass();
    System.GC.SuppressFinalize(cls);
    try
    {
        // use cls
    }
    finally
    {
        System.GC.ReRegisterForFinalize(cls);
    }
    As a general approach, the object shall be alive, from the point of view of the .NET Garbage Collector, to avoid potential NullPointerException in the JVM: https://jnet.masesgroup.com/articles/usage.html#suppressfinalizereregisterforfinalize-pattern
Inheritance Hierarchy
SystemObject
  MASES.JCOBridge.C2JBridgeJVMBridgeCoreDisposable

Namespace: MASES.JCOBridge.C2JBridge
Assembly: C2JBridge (in C2JBridge.dll) Version: 2.6.8.260410-ed5cc0c79218460f1e6b936e4bd65778f0bb23e9
Syntax
public class JVMBridgeCoreDisposable : IDisposable

The JVMBridgeCoreDisposable type exposes the following members.

Methods
 NameDescription
Public methodStatic memberCreate Returns an instance of JVMBridgeCoreDisposable managing classToDispose
Public methodDisposePerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalize Finalize the JVMBridgeCoreDisposable instance
(Overrides ObjectFinalize)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Operators
 NameDescription
Public operatorStatic member(JVMBridgeCore to JVMBridgeCoreDisposable) Implicitly converts a JVMBridgeCore instance into a JVMBridgeCoreDisposable instance
Top
Extension Methods
 NameDescription
Public Extension MethodConvertTReturn Converts a generic object
(Defined by JCOBridgeExtensions)
Public Extension MethodToNative Converts a generic input to an object manageable from the JVM
(Defined by JCOBridgeExtensions)
Top
Example
This is a basic example showing JVMBridgeCoreDisposable class usage
C#
class TheClass : JVMBridgeCore<TheClass>
{
    public override string BridgeClassName => "org.company.TheClass";

    public TheClass()
    {
    }
}

var cls = new TheClass();
using var disposable = JVMBridgeCoreDisposable.Create(cls);
See Also