Reputation: 694
I did some test with non-used units. There is no clear exe size difference by my testing. But I can't find any information in the document. My question is, will non-used unit uses increase the output file size?
Upvotes: 3
Views: 212
Reputation: 643
When you add some unused units into the “uses part” of your code it’s not good practice, but it increases the size of the final exe-file by itself. Compiler analyzes the whole code and cuts off all unused parts, so it increases compilation time. But you need to remember one tricky thing – non-uses units can contain code-parts that can be used not in a direct way. It can be the “initialization part” of a unit or some “Class constructors” that can be triggered automatically, so the compiler will include it(and all chains of used types/units) into your exe-file. One more thing – when you compile some bpl-file – compiler optimization does not work in the same way, because it can not know what you will use from this bpl in future projects which will use this bpl.
P.S. If you want to know what units are really used in your application and how initialization works– you can place a breakpoint in “system.pas”, procedure InitUnits. There you can see unitCount and can step into initialization part of all used by your application (even see sources, if it’s available in your Delphi edition)
Upvotes: 3