public void remove(final long address, final int length) {
    Preconditions.checkArgument(address >= 0, "Error: Address can't be less than 0");
    Preconditions.checkArgument(length > 0, "Error: Length must be positive");

    try {
      m_writeLock.lock();

      final MemoryChunk chunk = findChunk(address);

      if (chunk == null) {
        // There is no chunk with the selected address. Now we have
        // to find out whether the gap to the next chunk is small enough
        // to delete some data from the next chunk.

        final MemoryChunk nextChunk = findNextChunk(address);

        if (nextChunk == null) {
          // There is no next chunk => nothing to delete
          return;
        } else if (nextChunk.getAddress() < (address + length)) {
          // There is some data in the next chunk that must be removed
          final int toRemove = (int) ((address + length) - nextChunk.getAddress());

          remove(nextChunk.getAddress(), toRemove);
        } else {
          // There is a next chunk but it's too far away. No data
          // must be deleted there.
          return;
        }
      } else if (chunk.getAddress() == address) {
        if (chunk.getLength() <= length) {
          // The chunk has the same address as the memory region to remove
          // and the memory region to remove is at least as big as the chunk.

          // Remove the chunk itself because it's completely covered by the memory region
          removeChunk(chunk);

          // If there are bytes left to delete, continue in the next chunk
          final int toDelete = length - chunk.getLength();

          if (toDelete > 0) {
            remove(address + chunk.getLength(), toDelete);
          }
        } else
        // if (chunk.getLength() > length)
        {
          // The chunk has the same address as the memory region
          // to remove but the chunk is larger. Get rid of the first
          // part of the chunk but keep the second part.

          // Split the chunk into a chunk that's deleted and a chunk that's kept
          splitChunk(chunk, address + length);

          // Remove the first chunk of the split operation
          removeChunk(findChunk(address));
        }
      } else {
        if ((chunk.getAddress() + chunk.getLength()) <= (address + length)) {
          // The chunk does not have the same address as the memory
          // region to delete but the chunk ends at least at the address
          // of the memory region.
          // In this case we keep the first part of the chunk and
          // delete the last part.

          // Split the chunk into a chunk that's kept and a chunk that's deleted
          splitChunk(chunk, address);

          // Remove the second chunk of the split operation
          final MemoryChunk deleteChunk = findChunk(address);
          removeChunk(deleteChunk);

          // If there are bytes left to delete, continue in the next chunk
          final int toRemove = length - deleteChunk.getLength();

          if (toRemove > 0) {
            // Remove the remaining bytes from the next chunk
            remove(address + deleteChunk.getLength(), toRemove);
          }
        } else
        // if (chunk.getAddress() + chunk.getLength() > address + length)
        {
          // The chunk does not have the same address as the memory region
          // and the chunk has a later end address. This means some part from
          // the middle of the chunk must be deleted.

          // Split the chunk into one part that's kept and one part that's partially removed
          splitChunk(chunk, address);

          // Split the second chunk again because it's partially deleted too
          final MemoryChunk secondChunk = findChunk(address);
          splitChunk(secondChunk, address + length);

          // The middle part can now be deleted
          removeChunk(findChunk(address));
        }
      }
    } finally {
      m_writeLock.unlock();
    }
  }
Removes a memory region from the memory.

@param address Start of the memory region to remove.
@param length Length of the memory region to remove.
java/zylib/src/main/java/com/google/security/zynamics/zylib/general/memmanager/Memory.java