Create Resources on Demand
This is an approach which must be followed when designing a scalable web application. The general rule here is to create resource-sensitive objects when they are needed, not before, and destroy them when they are no longer needed.
One example is database tables. As described in the previous section, database tables can load many rows at once, which can increase memory usage with increased number of rows. It is true especially with memory datasets. Delphi's built-in TClientDataset is an example of a memory dataset. In order to make sure a dataset is created and loaded with data when it is needed, it is good to place the dataset on a form or frame where DB-aware controls exist. Each time the user needs to visit that form, it will be created and shown along with tables and DB-aware controls. When the user closes the form, the dataset will be freed and its memory is sent back to the application memory pool.
The method can be applied to reporting tools. Instead of putting report components on MainModule, it can be created just before generating the report and destroyed right after the report is generated and saved in a temporary file.