Most of my spare time (yes, I have a job, too:), I spend working on framework components. A few weeks ago I started to create a nice – new kind of – application framework for Silverlight.
I have some clients who like the idea of remote editing and configuration, so I decided to bring some .NET to the browser. The framework is based on the Meta Mediator and Properties First pattern and already contains some UI components, automatic layout management, animation support at property granularity … the usual stuff you need to create for visual editing components.
Its core is based on a change notification mechanism that works by a per object subscription method to wire event handling.
Everything worked out, object observation is truly transparent and so layer separation (for example model / view) is possible without additional effort. But because dependencies introduced by change notification are hidden and “upper” layers refer to lower ones, most connections are effectively bidirectional from the perspective of the garbage collector.
And that introduces, well, memory leaks, and even more problematic, change notification paths that are triggered even when objects are not used anymore.
The problem of bidirectional dependencies in GC environments, especially in user interfaces, exists for a long time and has not been solved effectively (for what I know). There are “weak references”, which solve merely the memory leakage, but change propagation will continue to happen until the GC runs. No solution for an environment where the execution time for changes are crucial.
I scratched my head for a few days, but now, I think I found a solution:
Cells: The conceptual solution for an automatic grouping of objects which is capable to track object construction and all implicit references to foreign cells (the back-references created by the change notification system). This seems to be promising. You create a new cell context, all objects implicitly belong to that cell and if you destroy it, all implicit references are disconnected, no change notification will reach the cell anymore, and the GC is able to free it.
I think the idea is great, at least in theory, I have not implemented it yet: It is natural, only references to foreign cells must be tracked and it can be visualized and debugged easily.
inspired by nature
yours
armin