Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
In order to save browser memory, should I destroy bootstrap tooltips array after I rendered new tooltips?

I apologize if it is a duplicate question, but I googled first without getting a useful answer.

Scenary

I was doing a search results display work, and every search result has a button that renders tooltips, here is the simplified code, they are already working fine for me:

let searchAndDisplayResults = (function () {
    let tooltips;
    return (key) => {
        // search results container
        let searchContainer = $('.search-results-container');
        // clear elements first
        searchContainer.html('');
        // get search results information array
        let searchedResultsArray = getSearchedResults(key);
        // render search results to page(simplified)
        searchedResultsArray.forEach((ele) => {
              searchContainer.append(`<div>${ele}</div><i class='bi-plus' data-bs-toggle="tooltip" title="Some hint for this button"></i>`);
        }
        // enable tooltip
        tooltips = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')).map(tooltipTriggerEl => { return new bootstrap.Tooltip(tooltipTriggerEl) });
    }
})();

Note: the code that enables tooltips above is from here.
Every time new search key was passed into the function, old search results' elements will be destroyed and new search results will be re-rendered, but it seems it remains variable tooltips not to delete every time search results were re-rendered.

Question

So in order to save browser memory consuming, I wonder if I need to delete tooltips array everytime search results were re-rendered? For example, should I use code like this below to destroy variable tooltips everytime new search results to be rendered?

if (tooltips != null) {
    for (let tooltip of tooltips) {
        delete tooltip;
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No, you don't need to. Doing tooltips = something will remove the reference from the old tooltips array. As long as there aren't any other references to tooltips, it will be garbage collected.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda