Does the delete use delete in the exampleArray[i] index, for example, for the subsequent exampleArray.push() to increase the memory consumption of the array object?
push increases memory consumption regardless of whether delete precedes it. Usually. If the engine has a pre-allocated storage for additional items, this may not be the case. If you think that the engine can somehow reuse the space open by delete to avoid allocating additional memory for the next push , most likely it will not.
How does deleting an item affect the garbage collector?
A deleted item obeys the GC if it does not remain in scope.
Is there a more efficient way to get rid of an exampleArray element of an element?
You have to decide whether you decide or not to end up with a sparse array. If you do not, and as you specify forEach , etc. Skip the holes, then delete will be faster. If you want to compress the array around the element to be deleted, for example, splice , the cost is likely to be 2 times higher.
Engines implement different strategies for representing arrays internally and sometimes switch between them - for example, when an array reaches a certain degree of sparseness. Each engine will have a different strategy. The only reliable way to answer these performance questions is to run performance tests or read the engine source code.
The key point in GC is that you do not need to worry about it. You do not want to invade the engine. You can optimize one engine and find that performance on another engine has deteriorated.
All these micro-optimization issues are relevant only when you have logic that includes huge data objects on which you execute millions of statements. If so, you might want to flip your own data structure.
user663031
source share