Wpis z mikrobloga

#javascript #webdev

Źródło: https://blog.sessionstack.com/how-javascript-works-memory-management-how-to-handle-4-common-memory-leaks-3f28b94cfbec

Po 1. Pkt 3. O co mirki chodzi w tym zdaniu: The thing to remember is that once a scope for closures is created for closures in the same parent scope, the scope is shared.

i po 2. W pkt. 4: If you store a reference to each DOM row in a dictionary or an array, there will be two references to the same DOM element: one in the DOM tree and another in the dictionary. If you decide to get rid of these rows, you need to remember to make both references unreachable.

Rozumiem usuwanie w JS ale, co ma na myśli "you need to remember to make both references unreachable."
  • 1
@ziolo86: 2. Jeśli masz jakiś element w drzewie DOM i trzymasz też referencje do niego w jakiejś dodatkowej tablicy, to usuwając ten element z DOMu musisz pamiętać, żeby usunąć też referencje z tej tablicy (czyli spowodować żeby była "unreachable"). Jeśli tego nie zrobisz, GC nie będzie w stanie usunąć tego elementu z pamięci (mimo że nie będzie go już w drzewie DOM) właśnie z powodu tej referencji, bo będzie myślał że