"To optimize memory usage, instances should be as short-lived as possible. In this case, we can make the newly created Cell instances much more short-living by not storing a reference to them in the cells array. Instead we can simply use the newly created instance to update the instance already in the array.
The cell class provides a method named updatecell, chich updates a Cell using another one."
However i donÂ´t understand which is the difference betwen update a existing cell versus store the new cell in the array. When the new Cell is stored in the array the old cell is not referenced anymore and may be Garbage collected.
However is a fact that updating the cell seems to use best the memory. But i donÂ´t understand the reason.
Thanks in advanced and excuse my bad english.
Code: Select all
// This assignment will overwrite the reference to the old cell at [c, r], // making the old cell eligible for GC. cells[ c, r ] = newCell;
In the modified code, the newly created cell is only used to update the "old" cell, and then the newly created cell can be GCed.
The point that we try to make in the tutorial is that even though the number of allocations is the same, and the number of live instances is the same, the memory utilization will be much better in the modified code, since the newly created instances are much more short-lived.
SciTech Software AB
Users browsing this forum: No registered users and 22 guests