@Override
  public void clearWithExecutor(Executor executor) {
    ArrayList<HashEntry<?, ?>> entries = null;
    try {
      for (final Segment<K, V> segment : segments) {
        entries = segment.clear(entries);
      }
    } finally {
      if (entries != null) {
        final ArrayList<HashEntry<?, ?>> clearedEntries = entries;
        Runnable runnable;
        if (OffHeapClearRequired.doesClearNeedToCheckForOffHeap()) {
          runnable = () -> {
            for (HashEntry<?, ?> he : clearedEntries) {
              for (HashEntry<?, ?> p = he; p != null; p = p.getNextEntry()) {
                if (p instanceof RegionEntry) {
                  synchronized (p) {
                    GatewaySenderEventImpl.release(((RegionEntry) p).getValue()); // OFFHEAP
                  }
                }
              }
            }
          };
        } else {
          runnable = () -> {
            for (HashEntry<?, ?> he : clearedEntries) {
              for (HashEntry<?, ?> p = he; p != null; p = p.getNextEntry()) {
                synchronized (p) {
                  ((OffHeapRegionEntry) p).release();
                }
              }
            }
          };
        }
        boolean submitted = false;
        if (executor != null) {
          try {
            executor.execute(runnable);
            submitted = true;
          } catch (RejectedExecutionException e) {
            // fall through with submitted false
          } catch (CancelException e) {
            // fall through with submitted false
          } catch (NullPointerException e) {
            // fall through with submitted false
          }
        }
        if (!submitted) {
          String name = getClass().getSimpleName() + "@" + hashCode() + " Clear Thread";
          Thread thread = new LoggingThread(name, runnable);
          thread.start();
        }
      }
    }
  }
{@inheritDoc}

@return the previous value associated with the specified key, or <tt>null</tt> if there was no
        mapping for the key
@throws NullPointerException if the specified key or value is null
geode-core/src/main/java/org/apache/geode/internal/util/concurrent/CustomEntryConcurrentHashMap.java