# TODO: looks like it needs to account for the case where top of stack is a string of pushes, but there are runs of pushes without corresponding pops (yet?) deeper in the stack
# TODO: seems this is possible, but check if it really is:
#for index, ev in enumerate(self.stack_events[::-1]):
# if ev[0] == StackEvent.POP:
# last_pop = index
# The list of stack events is split up into two kinds of "runs", runs of "push" events which don't have a corresponding "pop" yet
# And runs of push/pop events which are assumed to be balanced
# These latter can be straightforwardly accounted for by recursively removing the "outer" frame corresponding to a push/pop pair
# "push" events are trickier, because to get the allocations, they need to be compared to the *next* time hammer memory stats were sampled, be it push or pop
# TODO: perhaps a "pop" should act as a checkpoint, and commit every allocation up to that point
defcalculate_and_clear_pushes_at_end(self):
# Throws StopIteration if no more items in the iterator match the condition