Ticket #321 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Nullify DOM event handlers and object references to avoid memory leaks

Reported by: JeremyRuston Owned by:
Priority: undefined Milestone: 2.2
Component: core Version:
Severity: undefined Keywords:
Cc:

Description (last modified by JeremyRuston) (diff)

TiddlyWiki already goes to some lengths to minimise  browser memory leaks:

  • Only primitive types are ever stored in DOM custom properties (also called expando properties)
  • Event handlers are defined without using closures

The impact of these measures is quite severe, and is increasingly making it harder to create fluid implementations of more complex UI logic.

It is proposed to introduce a "DOM scrubbing" utility to TiddlyWiki that will allow the above rules to be relaxed. DOM scrubbing involves iterating through DOM nodes before deletion, nullifying any event handlers or custom properties. This allows JavaScript?'s memory manager to free the target objects when it can, avoiding memory leaks.

The consequences of this change are quite far-reaching. On the upside:

  • JavaScript? objects can be freely stored in custom DOM properties
  • Event handlers can use closures to capture the context on which they need to operate

On the downside:

  • All nodes must be scrubbed before deletion. In practical terms this means that the removeChildren() or removeNode() utility functions should be used in preference to the underlying DOM functions removeChild() and replaceNode()
  • The entire document tree must be scrubbed on the onload() event handler

Change History

Changed 3 years ago by JeremyRuston

  • description modified (diff)

Changed 3 years ago by SaqImtiaz

  • status changed from new to closed
  • resolution set to fixed

Implemented in TiddlyWiki 2.2 Some documentation on the DOM Scrubbing would be good, so developers know to use the utility functions.

Note: See TracTickets for help on using tickets.