Source:
<code>public void run(String mapName, Predicate predicate, int partitionId, Result result) { PagingPredicateImpl pagingPredicate = predicate instanceof PagingPredicateImpl ? (PagingPredicateImpl) predicate : null; PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId); MapContainer mapContainer = mapServiceContext.getMapContainer(mapName); RecordStore<Record> recordStore = partitionContainer.getRecordStore(mapName); boolean nativeMemory = recordStore.getInMemoryFormat() == InMemoryFormat.NATIVE; boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer, partitionId); Extractors extractors = mapServiceContext.getExtractors(mapName); StoreAdapter storeAdapter = new RecordStoreAdapter(recordStore); Map.Entry<Integer, Map.Entry> nearestAnchorEntry = pagingPredicate == null ? null : pagingPredicate.getNearestAnchorEntry(); recordStore.forEachAfterLoad(new BiConsumer<Data, Record>() { LazyMapEntry queryEntry = new LazyMapEntry(); @Override public void accept(Data key, Record record) { Object value = useCachedValues ? getValueOrCachedValue(record, ss) : record.getValue(); if (value == null) { return; } key = toHeapData(key); value = nativeMemory ? toHeapData((Data) value) : value; <START> queryEntry.init(ss, key, value, extractors); <END> queryEntry.setRecord(record); queryEntry.setStoreAdapter(storeAdapter); queryEntry.setMetadata(PartitionScanRunner.this.getMetadataFromRecord(recordStore, key, record)); if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) { result.add(queryEntry); queryEntry = new LazyMapEntry(); } } }, false); result.orderAndLimit(pagingPredicate, nearestAnchorEntry); }</code><technical_language>In order avoid crash, copy key/value heap eagerly. However, predicate is applied here, copying avoided for discarded entries. is, apply predicate offheap data, copy heap if predicate evaluates true. @ahmetmircik @taburet do think</technical_language>

Target:
public void run(String mapName, Predicate predicate, int partitionId, Result result) { PagingPredicateImpl pagingPredicate = predicate instanceof PagingPredicateImpl ? (PagingPredicateImpl) predicate : null; PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId); MapContainer mapContainer = mapServiceContext.getMapContainer(mapName); RecordStore<Record> recordStore = partitionContainer.getRecordStore(mapName); boolean nativeMemory = recordStore.getInMemoryFormat() == InMemoryFormat.NATIVE; boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer, partitionId); Extractors extractors = mapServiceContext.getExtractors(mapName); StoreAdapter storeAdapter = new RecordStoreAdapter(recordStore); Map.Entry<Integer, Map.Entry> nearestAnchorEntry = pagingPredicate == null ? null : pagingPredicate.getNearestAnchorEntry(); recordStore.forEachAfterLoad(new BiConsumer<Data, Record>() { LazyMapEntry queryEntry = new LazyMapEntry(); @Override public void accept(Data key, Record record) { Object value = useCachedValues ? getValueOrCachedValue(record, ss) : record.getValue(); if (value == null) { return; } queryEntry.init(ss, key, value, extractors); queryEntry.setRecord(record); queryEntry.setStoreAdapter(storeAdapter); queryEntry.setMetadata(PartitionScanRunner.this.getMetadataFromRecord(recordStore, key, record)); if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) { value = nativeMemory ? toHeapData((Data) value) : value; result.add(queryEntry.init(ss, toHeapData(key), value, extractors)); queryEntry = new LazyMapEntry(); } } }, false); result.orderAndLimit(pagingPredicate, nearestAnchorEntry); }