Source:
<code>private static STRtree buildRTree(LongArrayList addresses, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, LocalMemoryContext localUserMemoryContext) { STRtree rtree = new STRtree(); Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate); long estimatedMemorySizeInBytes = 0; long lastUpdatedMemorySizeInBytes = 0; for (int position = 0; position < addresses.size(); position++) { long pageAddress = addresses.getLong(position); int blockIndex = decodeSliceIndex(pageAddress); int blockPosition = decodePosition(pageAddress); Block block = channels.get(geometryChannel).get(blockIndex); if (block.isNull(blockPosition)) { continue; } Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition)); OGCGeometry ogcGeometry = deserialize(slice); verify(ogcGeometry != null); if (ogcGeometry.isEmpty()) { continue; } double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0); if (radius < 0) { continue; } if (!radiusChannel.isPresent()) { accelerateGeometry(ogcGeometry, relateOperator); } int partition = -1; if (partitionChannel.isPresent()) { Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex); partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition)); } GeometryWithPosition geometryWithPosition = new GeometryWithPosition(ogcGeometry, partition, position); rtree.insert(getJtsEnvelope(ogcGeometry, radius), geometryWithPosition); <START> estimatedMemorySizeInBytes += ENVELOPE_INSTANCE_SIZE + geometryWithPosition.getEstimatedMemorySizeInBytes(); <END> if (estimatedMemorySizeInBytes - lastUpdatedMemorySizeInBytes >= 100_000_000) { localUserMemoryContext.setBytes(estimatedMemorySizeInBytes); lastUpdatedMemorySizeInBytes = estimatedMemorySizeInBytes; } } rtree.build(); return rtree; }</code><technical_language>is array of references collecting geometries rtree. 100% accurate, add size of object reference time well</technical_language>

Target:
private static Flatbush<GeometryWithPosition> buildRTree(LongArrayList addresses, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, LocalMemoryContext localUserMemoryContext) { Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate); ObjectArrayList<GeometryWithPosition> geometries = new ObjectArrayList<>(); long recordedSizeInBytes = localUserMemoryContext.getBytes(); long addedSizeInBytes = 0; for (int position = 0; position < addresses.size(); position++) { long pageAddress = addresses.getLong(position); int blockIndex = decodeSliceIndex(pageAddress); int blockPosition = decodePosition(pageAddress); Block block = channels.get(geometryChannel).get(blockIndex); if (block.isNull(blockPosition)) { continue; } Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition)); OGCGeometry ogcGeometry = deserialize(slice); verify(ogcGeometry != null); if (ogcGeometry.isEmpty()) { continue; } double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0); if (radius < 0) { continue; } if (!radiusChannel.isPresent()) { accelerateGeometry(ogcGeometry, relateOperator); } int partition = -1; if (partitionChannel.isPresent()) { Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex); partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition)); } GeometryWithPosition geometryWithPosition = new GeometryWithPosition(ogcGeometry, partition, position, radius); geometries.add(geometryWithPosition); addedSizeInBytes += geometryWithPosition.getEstimatedSizeInBytes(); if (addedSizeInBytes >= MEMORY_USAGE_UPDATE_INCREMENT_BYTES) { localUserMemoryContext.setBytes(recordedSizeInBytes + addedSizeInBytes); recordedSizeInBytes += addedSizeInBytes; addedSizeInBytes = 0; } } return new Flatbush<>(geometries.toArray(new GeometryWithPosition[] {})); }