Javascript delete object

Please excuse my question if it does not make much sense.

I use javascript to create a dom element for this I create an object ( obj ={}) and populate the properties when I go, one of which is the dom element that needs to be created. as soon as an element is created and added to the document, I do not need an object to occupy any space in memory, so I thought I should delete it. how would i do that? thank

+3
source share
3 answers

The object that will exist in memory as soon as it is in the DOM, and the obj property that holds it, does contain a reference to it, not a copy. As far as I know, the memory needed to save the link as a property of obj should be negligible. In this case, I would not worry about deleting it at all.

+3
source

here's how:

my_var = null;

//or remove it
delete my_var;
+3
source

if you define an object as a language, for example

var obj = {}

it will be automatically undefined at the end of the function.

0
source

Source: https://habr.com/ru/post/1728896/


All Articles