babyloneleven·7년 전·discussCompilers of managed languages already do this optimization when they can prove that a variable has a static lifetime. Look up scape analysis.The trouble is, this is hard to do for non-trivial code (and in the general case is uncomputable).