Skip to content

Commit

Permalink
Use static lambda in WorkProcessorOperatorAdapter
Browse files Browse the repository at this point in the history
Avoid capturing a local reference to "this" which can retain memory in
the operator info supplier longer than intended.
  • Loading branch information
pettyjamesm committed Jul 16, 2024
1 parent 8c0b623 commit 24bf424
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.trino.memory.context.MemoryTrackingContext;
import io.trino.spi.Page;

import java.util.function.Supplier;

import static java.util.Objects.requireNonNull;

/**
Expand Down Expand Up @@ -101,7 +103,13 @@ public WorkProcessorOperatorAdapter(OperatorContext operatorContext, AdapterWork
memoryTrackingContext.initializeLocalMemoryContexts(workProcessorOperatorFactory.getOperatorType());
this.workProcessorOperator = workProcessorOperatorFactory.createAdapterOperator(new ProcessorContext(operatorContext.getSession(), memoryTrackingContext, operatorContext));
this.pages = workProcessorOperator.getOutputPages();
operatorContext.setInfoSupplier(() -> workProcessorOperator.getOperatorInfo().orElse(null));
operatorContext.setInfoSupplier(createInfoSupplier(workProcessorOperator));
}

// static method to avoid capturing a reference to "this"
private static Supplier<OperatorInfo> createInfoSupplier(AdapterWorkProcessorOperator workProcessorOperator)
{
return () -> workProcessorOperator.getOperatorInfo().orElse(null);
}

@Override
Expand Down

0 comments on commit 24bf424

Please sign in to comment.