Skip to content
Discussion options

You must be logged in to vote

Bootstrap 5 uses a nested Map structure in its internal Data module (src/dom/data.js). Here's how it works:

Map<HTMLElement, Map<string, ComponentInstance>>
  • The outer Map is keyed by DOM elements
  • The inner Map is keyed by a component name string (e.g. "bs.modal", "bs.tooltip")
  • Each element can only have one instance per component type

When you call Modal.getInstance(element), it looks up the element in the outer Map, then retrieves the "bs.modal" entry from the inner Map. getOrCreateInstance does the same but creates a new instance if one doesn't exist.

Garbage collection — the important part

No, instances are NOT automatically garbage-collected when you remove the element from the DOM.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@o-alquimista
Comment options

Answer selected by o-alquimista
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants