private static synchronized void addInstance(BufferMgr bufMgr) {

		if (openInstances == null) {

			openInstances = new HashSet<>();

			Runnable cleanupTask = () -> {
				BufferMgr[] instanceList;
				synchronized (BufferMgr.class) {
					instanceList = openInstances.toArray(new BufferMgr[openInstances.size()]);
				}
				for (BufferMgr bufferMgr : instanceList) {
					try {
						bufferMgr.dispose(true);
					}
					catch (Throwable t) {
						// Ignore errors
					}
				}
			};
			ShutdownHookRegistry.addShutdownHook(cleanupTask,
				ShutdownPriority.DISPOSE_FILE_HANDLES);
		}
		openInstances.add(bufMgr);
	}
Add new BufferMgr instance and ensure that all non-disposed
BufferMgr instances are properly disposed when the VM shuts-down.
@param bufMgr new instance
Ghidra/Framework/DB/src/main/java/db/buffers/BufferMgr.java