/** * All bag implementations that can get big enough to be spilled * should call this method after every time they add an element. */ protected void markSpillableIfNecessary() { if (!spillableRegistered) { long estimate = getMemorySize(); if ( estimate >= SPILL_REGISTER_THRESHOLD) { SpillableMemoryManager.getInstance().registerSpillable(this); spillableRegistered = true; } } }