Clear live references to info suppliers in OperatorContext#destroy()
Memoizes the results of and then clears any references to OperatorInfo
suppliers in OperatorContext#destroy() to avoid accidentally retaining
references to potentially large objects like Operators themselves
after they have been closed.
@@ -24,6 +24,7 @@ import com.facebook.presto.operator.OperationTimer.OperationTiming;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.plan.PlanNodeId;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Suppliers;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
@@ -333,6 +334,13 @@ public class OperatorContext
memoryRevocationRequestListener = null;
}
+ // memoize the result of and then clear any reference to the original suppliers (which might otherwise retain operators or other large objects)
+ Supplier<? extends OperatorInfo> infoSupplier = this.infoSupplier.get();
+ if (infoSupplier != null) {
+ OperatorInfo info = infoSupplier.get();
+ this.infoSupplier.set(info == null ? null : Suppliers.ofInstance(info));
+ }
+
operatorMemoryContext.close();
if (operatorMemoryContext.getSystemMemory() != 0) {
