code: public ByteBuffer markLocalToBeCleared(ByteBuffer context)
      {
          short count = context.getShort(context.position());
          if (count <= 0)
              return context; // already marked or all are remote.
  
          boolean hasLocalShards = false;
          for (int i = 0; i < count; i++)
          {
              if (context.getShort(context.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH) >= 0)
              {
                  hasLocalShards = true;
                  break;
              }
          }
  
          if (!hasLocalShards)
              return context; // all shards are global or remote.
  
          ByteBuffer marked = ByteBuffer.allocate(context.remaining());
          marked.putShort(marked.position(), (short) (count * -1));
          ByteBufferUtil.arrayCopy(context,
                                   context.position() + HEADER_SIZE_LENGTH,
                                   marked,
                                   marked.position() + HEADER_SIZE_LENGTH,
                                   context.remaining() - HEADER_SIZE_LENGTH);
          return marked;
      }
docs: Mark context to delete local references afterward.
  Marking is done by multiply #elt by -1 to preserve header length
  and #elt count in order to clear all local refs later.
  
  @param context a counter context
  @return context that marked to delete local refs