fix($compile): Resolve various potential memory leaks (v1.2.x)

Related to #9199
Related to #9079
Related to #8504
Related to #9197