    /** Clear all registered {{ trait_pascal }} implementations. */
    public static void {{ method_name }}() throws Exception {
        try {
            try (var arena = Arena.ofShared()) {
                MemorySegment outErr = arena.allocate(ValueLayout.ADDRESS);
                int rc = (int) (long) NativeLib.{{ prefix_upper }}_CLEAR_{{ trait_snake_upper }}.invoke(outErr);
                if (rc != 0) {
                    MemorySegment errPtr = outErr.get(ValueLayout.ADDRESS, 0);
                    String msg = errPtr.equals(MemorySegment.NULL) ? "clear failed (rc=" + rc + ")" : errPtr.reinterpret(Long.MAX_VALUE).getString(0);
                    throw new RuntimeException("{{ method_name }}: " + msg);
                }
            }
        } catch (Throwable t) {
            if (t instanceof Exception e) {
                throw e;
            } else {
                throw new RuntimeException("Unexpected error during clear", t);
            }
        }
        {{ registry_field }}.values().forEach({{ bridge_class }}::close);
        {{ registry_field }}.clear();
    }
