Although this is not a garbage collection algorithm, escape analysis allows you to talk about the lifetime of objects. Thus, if efficiency is a problem, and objects should not be collected in all, but in the “obvious” cases, this can be convenient. The main idea is to perform a static analysis of the program (during compilation or during loading, if it was compiled for a virtual machine) and find out whether the newly created object can avoid the execution of the procedure in which it was created (hence the name of the analysis), If the object is not transferred anywhere, is not stored in global memory, is not returned from this procedure, etc., it can be freed before returning from this procedure or even earlier, in the place of its last use.
Objects that do not live longer than the associated method call can be allocated on the stack rather than on the heap so that they can be removed from the garbage collection cycle during compilation, thereby reducing pressure on the overall GC.
source share