Changing site:mode throws Twig memory error
You're debugging an entity or other object somewhere that has recursive references and debug gets into an endless recursion until all memory is used up.

Instead of debug(node) or similar, use debug(node.toArray()), that gives you the raw value instead of huge object structures.