Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
How to remove library from memory in JavaScript?

There are multi libraries that each of them generates some HTML elements which runs separately such that by running one library first the elements created by the previous library must be removed then new elements will generated. It's worked fine, the elements removed correctly and new ones created correctly.

But there is a problem : the previous library that runs, again exist in the memory and listen to events. How can I dispose that from memory ?

import { LeftSidebarEditor } from './editor/LeftSidebar.Editor.js';
import { LeftSidebarSupport } from './support/LeftSidebar.Support.js';

function LeftSidebar(editor) {

    var signals = editor.signals;

    var container = new UIPanel();
    container.setId('left-sidebar-menu');

    var item = new LeftSidebarEditor(editor);

    container.add(item);

    signals.scopeChanged.add(function (scope) {

        editor.currentScope = JSON.stringify(scope);
        // remove all elements
        container.clear();

        item = null;

        switch (scope) {

             case 'editor':
                // container.add(new LeftSidebarEditor(editor));
                item = new LeftSidebarEditor(editor);

                container.add(item);
                break;

            case 'support':
                // container.add(new LeftSidebarSupport(editor));
                item = new LeftSidebarSupport(editor);

                container.add(item);
                break;

        }

    });

    return container;

}

LeftSidebarSupport

class LeftSidebarSupport {

    constructor(editor) {

        let counter = 0;
        setInterval(() => {
            console.log('I am alive from support', counter++);
        }, 2000);

         signals.objectSelected.add(function (object) {

        if (object != null) {

            return;
        }

        const selected = document.querySelector('#left-sidebar-menu li.selected');
        if (selected){
            let selected_attr =  selected.getAttribute('data-tooltip');
            if (selected_attr!='Tag'){
                removeAllSelected();
            }
        }

    });


        function removeAllSelected() {

        const selected = document.querySelector('#left-sidebar-menu li.selected');

        if (selected) {

            selected.classList.remove('selected');

        }

    }

    }
}

By change the signal from support to editor again the logs printed which must be stopped !! I want by switching between scopes just exist current scope library in memory and others removed entirely.

I am alive from support 89
I am alive from support 90
I am alive from support 91
I am alive from support 92
I am alive from support 93

Pleas, note !

There really is no interval, but exist a piece of code that removes a class from the elements. For simplicity, the interval example is used here. The basis of my question is why can LeftSidebarSupport running again?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda