Memory consumption
.Net Grid consumes memory while adding a number of rows. This example calculates size of memory allocated by the application while inserting/removing data objects. The calculation is approximate (to get an average value, add or remove a big number or rows: more than 10 000). Note that the Garbage Collector may be invoked at any time by CLR. This way, when all rows are removed, memory counter may differ from the initial state.
Memory consumption is a very critical characteristic of the product, although it has often been neglected by programmers who mainly pay attention to CPU resource consumption level. The fact is that memory is allocated for objects quite rapidly. However releasing this memory with Garbage Collector is a rather complicated process and may take much time. It is important to remember that during memory release operation the application becomes suspended (actually, all application threads become suspended), and as a result there is no activity in the application for a certain period.
Memory collection process usually takes less than a millisecond and is virtually unnoticeable for the end user, however with non-optimal memory allocation, this process may become too long might take several seconds. Besides, if the volume of physical memory (operating memory) becomes insufficient, operating system starts to allocate memory on a hard disk drive for temporary data storage. This process is known as memory swapping. Consequently, application may cause reduction of overall OS performance. If such application eventually consumes all virtual memory, the end user risks to encounter OutOfMemoryException exception.
.Net Grid tries to use memory as efficiently as possible. The grid uses less than 120 bytes (!) per row. This information includes: row position in the grid; hierarchy information; selection state, filtration information, reference to a business data...
In the current example, Data Object consists of ten System.Int32 fields: 4 bytes x 10 = 40 bytes. This way, in the sample form .Net Grid uses: 120 + 40 = 160 bytes (!). If the same object is used in several grids, you get significant memory gain and economy!
Just think about it – with modern computing scales when any home desktop computer has gigabytes of physical memory, only 16 megabytes (!) are used for 100,000 rows! It's really impressive!