JuggerNET Runtime Library v3.6.54.0  3.6.54.0
Public Member Functions | Protected Member Functions | Properties | List of all members
Codemesh.JuggerNET.JuggerNETProxyObject Class Reference

The baseclass for all non-exception types that are proxy types for Java types. More...

Inheritance diagram for Codemesh.JuggerNET.JuggerNETProxyObject:
Inheritance graph
[legend]
Collaboration diagram for Codemesh.JuggerNET.JuggerNETProxyObject:
Collaboration graph
[legend]

Public Member Functions

 JuggerNETProxyObject (string str)
 Initializes a proxy object that corresponds with a Java java.lang.String instance of the specified value. More...
 
 JuggerNETProxyObject (JNIHandle jobject)
 Initializes a proxy object that corresponds with a preexisting Java object represented by the given object handle. More...
 
void Dispose ()
 Releases the reference to the corresponding Java object, thereby making it eligible for garbage collection if no other references to the same object are held. More...
 
void Release ()
 Forgets the reference to the corresponding Java object. Unless caller explicitly cleans up Java reference, this will cause the runtime to leak a Java object reference. More...
 
override bool Equals (object obj)
 Implemented in terms of the Java equals() method. If the other object is not also a subclass of a JavaObject, the return value is always false. This is to ensure that the the results of a comparison is independent of the order, i.e. More...
 
override int GetHashCode ()
 Implemented in terms of the Java hashCode() method. More...
 
override string ToString ()
 Implemented in terms of the Java toString() method. More...
 
bool IsInstanceOf (JavaClass clazz)
 Returns true if the instance is type compatible with the given Java type. More...
 
bool IsSame (JavaProxy proxy)
 Returns true if the proxy instance wraps around the same Java object as the other proxy instance. More...
 

Protected Member Functions

 JuggerNETProxyObject ()
 Initializes a proxy object that corresponds with a Java null reference. More...
 

Properties

long JObject [get, set]
 A property giving access to the JNI object handle that represents the wrapped Java instance. More...
 
long JObjectDuplicate [get]
 A property representing a duplicated JNI object handle. More...
 
HandleRef Handle [get]
 
- Properties inherited from Codemesh.JuggerNET.JavaProxy
long JObject [get, set]
 A property representing the JNI object handle. More...
 
HandleRef Handle [get]
 A property representing the JNI object handle. More...
 
long JObjectDuplicate [get]
 A property representing a duplicated JNI object handle. More...
 

Detailed Description

The baseclass for all non-exception types that are proxy types for Java types.

All proxy objects implement the JavaProxy interface and are IDisposable. The fact that a proxy object is an IDisposable means that you can use instances derived of this type with the using directive.

By default, if you do nothing special, you will have to wait for the .NET garbage collector to run and call the Dispose() method as part of its cleanup process. This delay can cause you trouble under certain circumstances. It means that the .NET side might not call the Dispose() method for a long time because there are not many .NET objects that need to be collected.


On the Java side the picture may look quite different: the few .NET objects that are waiting to be collected might be hanging on to a lot of Java objects and your application might actually run out of Java heap space before the .NET garbage collector sees any reason to run.

This is not too common a scenario, but even without this scenario there are some possible negative consequences. As the Java objects are held on to longer than normal, they might migrate from an easily and efficiently collectable part of the heap into more expensive to collect areas of the heap. This can impact your application's performance.

You can prevent these problems by using a pattern such as this:

using( MyProxyType mpt = new MyProxyType() )
{
...
}

This pattern causes the .NET runtime to automatically call the Dispose() method when the scope of the using clause is exited. The Dispose() method takes care of freeing the Java reference so that the corresponding Java object will be eligible for garbage collection right away.

Constructor & Destructor Documentation

◆ JuggerNETProxyObject() [1/3]

Codemesh.JuggerNET.JuggerNETProxyObject.JuggerNETProxyObject ( )
inlineprotected

Initializes a proxy object that corresponds with a Java null reference.

◆ JuggerNETProxyObject() [2/3]

Codemesh.JuggerNET.JuggerNETProxyObject.JuggerNETProxyObject ( string  str)
inline

Initializes a proxy object that corresponds with a Java java.lang.String instance of the specified value.

Parameters
strthe string value.

References Codemesh.JuggerNET.JvmLoader.GetJvmLoader(), Codemesh.JuggerNET.IJvmLoader.JvmIfCreated, Codemesh.JuggerNET.JvmLoader.JvmLoaderIfCreated, and Codemesh.JuggerNET.IJvmLoader.Load().

◆ JuggerNETProxyObject() [3/3]

Codemesh.JuggerNET.JuggerNETProxyObject.JuggerNETProxyObject ( JNIHandle  jobject)
inline

Initializes a proxy object that corresponds with a preexisting Java object represented by the given object handle.

Parameters
jobjectthe object handle representing the already existing Java object.

Member Function Documentation

◆ Dispose()

void Codemesh.JuggerNET.JuggerNETProxyObject.Dispose ( )
inline

Releases the reference to the corresponding Java object, thereby making it eligible for garbage collection if no other references to the same object are held.

◆ Equals()

override bool Codemesh.JuggerNET.JuggerNETProxyObject.Equals ( object  obj)
inline

Implemented in terms of the Java equals() method. If the other object is not also a subclass of a JavaObject, the return value is always false. This is to ensure that the the results of a comparison is independent of the order, i.e.

a.Equals( b ) == b.Equals( a )

which could not be guaranteed if we did special things for obj being of some special .NET type.

Parameters
objthe object we're comparing for equality.
Returns

References Codemesh.JuggerNET.JavaMethod.CallBool().

◆ GetHashCode()

override int Codemesh.JuggerNET.JuggerNETProxyObject.GetHashCode ( )
inline

Implemented in terms of the Java hashCode() method.

Returns
The object's Java hashcode.

References Codemesh.JuggerNET.JavaMethod.CallInt().

◆ IsInstanceOf()

bool Codemesh.JuggerNET.JuggerNETProxyObject.IsInstanceOf ( JavaClass  clazz)
inline

Returns true if the instance is type compatible with the given Java type.

Parameters
clazzthe Java type.
Returns

Implements Codemesh.JuggerNET.JavaProxy.

References Codemesh.JuggerNET.JuggerNETProxyObject.JObject.

◆ IsSame()

bool Codemesh.JuggerNET.JuggerNETProxyObject.IsSame ( JavaProxy  proxy)
inline

Returns true if the proxy instance wraps around the same Java object as the other proxy instance.

Parameters
proxyThe other proxy instance.
Returns
True if the two proxies reference the same Java object.

Implements Codemesh.JuggerNET.JavaProxy.

◆ Release()

void Codemesh.JuggerNET.JuggerNETProxyObject.Release ( )
inline

Forgets the reference to the corresponding Java object. Unless caller explicitly cleans up Java reference, this will cause the runtime to leak a Java object reference.

Implements Codemesh.JuggerNET.JavaProxy.

◆ ToString()

override string Codemesh.JuggerNET.JuggerNETProxyObject.ToString ( )
inline

Implemented in terms of the Java toString() method.

Returns
the string representation of the object.

References Codemesh.JuggerNET.JavaMethod.CallString().

Property Documentation

◆ JObject

long Codemesh.JuggerNET.JuggerNETProxyObject.JObject
getset

A property giving access to the JNI object handle that represents the wrapped Java instance.

Referenced by Codemesh.JuggerNET.JuggerNETProxyObject.IsInstanceOf().

◆ JObjectDuplicate

long Codemesh.JuggerNET.JuggerNETProxyObject.JObjectDuplicate
get

A property representing a duplicated JNI object handle.

Accessing this property essentially duplicates the Java object handle. The returned handle needs to be released before the represented Java object can become eligible for garbage collection.


The documentation for this class was generated from the following file:

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.