}
}
FastIterator it = memory.getLeftTupleMemory().fullFastIterator();
for (LeftTuple leftTuple = betaNode.getFirstLeftTuple(memory.getLeftTupleMemory(), it); leftTuple != null; ) {
LeftTuple tmp = (LeftTuple) it.next(leftTuple);
if (context.getCleanupAdapter() != null) {
LeftTuple child;
while ((child = leftTuple.getFirstChild()) != null) {
if (child.getLeftTupleSink() == betaNode) {
// this is a match tuple on collect and accumulate nodes, so just unlink it
child.unlinkFromLeftParent();
child.unlinkFromRightParent();
} else {
// the cleanupAdapter will take care of the unlinking
context.getCleanupAdapter().cleanUp(child, workingMemory);
}
}
}
memory.getLeftTupleMemory().remove(leftTuple);
leftTuple.unlinkFromLeftParent();
leftTuple.unlinkFromRightParent();
leftTuple = tmp;
}
// handle special cases for Accumulate to make sure they tidy up their specific data
// like destroying the local FactHandles
if (object instanceof AccumulateMemory) {
((AccumulateNode) betaNode).doRemove(workingMemory, (AccumulateMemory) object);
}
if (!betaNode.isInUse()) {
it = memory.getRightTupleMemory().fullFastIterator();
for (RightTuple rightTuple = betaNode.getFirstRightTuple(memory.getRightTupleMemory(), it); rightTuple != null; ) {
RightTuple tmp = (RightTuple) it.next(rightTuple);
if (rightTuple.getBlocked() != null) {
// special case for a not, so unlink left tuple from here, as they aren't in the left memory
for (LeftTuple leftTuple = rightTuple.getBlocked(); leftTuple != null; ) {
LeftTuple temp = leftTuple.getBlockedNext();
leftTuple.setBlocker(null);
leftTuple.setBlockedPrevious(null);
leftTuple.setBlockedNext(null);
leftTuple.unlinkFromLeftParent();