There are some optimizations that do thus. When you know the object won't outlive the function, allocate it on thw stack instead of on the heap
And on the more extreme case you can even replace the objects with a bunch of local variables. For example, replace a Point object allocated on the stack with a pair of variables gor the x and y coordinates.
If you can answer that, then you can optimize accordingly.
E.g you can choose to allocate objects that won't be retained on the stack instead of the heap, or in separate blocks.
You can even potentially benefit from this even if you can't 100% know. If you use a generational collector, an object that almost certainly escapes could bypass the nursery, for example.