Fix a few problems in tuple codegen code. Fix #5069

Refs #5108
cached code could be corrupt if a backref memory location got reused