static void releaseMBeanServer() {
    try {
      // unregister all GemFire mbeans...
      for (final ObjectName name : mbeanServer.queryNames(null, null)) {
        if (name.getDomain().startsWith(DEFAULT_DOMAIN)) {
          unregisterMBean(name);
        }
      }

      // last, release the mbean server...
      MBeanServerFactory.releaseMBeanServer(mbeanServer);
      mbeanServer = null;
    } catch (JMRuntimeException e) {
      logStackTrace(Level.WARN, e);
    }
    /*
     * See #42391. Cleaning up the static maps which might be still holding references to
     * ManagedResources
     */
    synchronized (MBeanUtils.managedResources) {
      MBeanUtils.managedResources.clear();
    }
    synchronized (refreshClients) {
      refreshClients.clear();
    }
    /*
     * See #42391. Cleaning up the static maps which might be still holding references to
     * ManagedResources
     */
    synchronized (MBeanUtils.managedResources) {
      MBeanUtils.managedResources.clear();
    }
    synchronized (refreshClients) {
      refreshClients.clear();
    }
  }
Unregisters all GemFire MBeans and then releases the MBeanServer for garbage collection.
geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtils.java