Yes, the compiler can do that, but only for a whole program and with whole program optimization, a.k.a WPO and which is usually a three pass effort.
This is usually only worth it when the program is finished and debugged.
The above is the case for unused
methods in class or record. It optimizes away the vmt's.
See
https://wiki.freepascal.org/Whole_Program_OptimizationThe compiler itself is compiled that way.
What the compiler
always does at -O2 or higher is eliminate dead code, but the vmt's will then still be fully intact.