3 ms·
GUIs can easily use shallow trees for ownership. There's a natural harmony between the hierarchical composition of UIs and ownership hierarchy. E.g. Delphi's V
by barrkel 6y ago
GUIs can easily use shallow trees for ownership. There's a natural harmony between the hierarchical composition of UIs and ownership hierarchy.
E.g. Delphi's VCL has a simple and clear ownership mechanism. Components are owned by their Owner, which is either the Application (forms), a form (for almost all the controls on the form), or a control (for custom controls - normally nested controls are owned by the form). And there's a couple of eventing mechanisms to resolve peer reference relationships, and to negotiate dynamic control addition and removal. Unless you start adding components to collections or otherwise capturing long-term references to them (and you can use name-based access if you need a safe indirection), leaks and dangling references aren't that common.
Implementing that model in Rust, with usable borrows that stop you creating dangling references, isn't trivially obvious to me, but there are ways around, I think: message passing communication, passing closures in, or ephemeral trees which proxy access to the real UI tree.
- pjmlp 6y agoFrom my point of view all those approaches incur more performance issues than the traditional way, and closures only work if they are pure without keeping references to their parameters.