Disposing of a .NET Object

Disposing of a .NET Object

You can integrate the Java garbage collector with your .NET objects using javOnet. When you create an .NET object and store it in a Java variable, it will be handled in .NET process as long as your variable lives in the Java memory.

When Java collects the NObject object, this event is passed to .NET, and the corresponding .NET object is disposed and collected. If the .NET object implements the IDisposable interface, then the appropriate disposal procedure is followed.

You can also force object disposal by calling the “Dispose” method on the “NObject” object. javOnet exposes the dedicated “Dispose” method for closing all objects and releasing .NET memory. This method should be called only at the end of your Java application.

See Live Example!