The close Method

When your application terminates or no longer needs to use the spaces in a particular metaspace, it should disconnect from it using the metaspace’s close method.

The close method causes the application to properly leave all of the spaces to which it may still be joined in that metaspace, destroys any listeners or space browsers that may still exist on those spaces, and ultimately severs all network connections with the other members of the metaspace.

Each getSpace() function call increments the use count on an object. This use count ensures that a metaspace leave does not happen when there is a valid user space/browser/listener active. The user needs to leave/stop all these space/browsers/listeners to ensure that when Metaspace.close is used, metaspace disconnect happens as expected. This is the case both for Java and for C APIs.

You can forcibly close a metaspace connection even if there are still valid Space objects by using the closeAll method instead of the close method.

Related reference