added optional trimming to stack_memory