I'm trying to find out the memory usage of javascript Map objects that have ~20k entries - key is a string, and value is an array of 1-2 strings. I have created 2 Maps: with 17k and 22k entries. They both have the same memory usage in chrome profiler - how?
Why do Map objects differ in size only after Objects from which they are created get removed from the scope? Also, i know how hashmaps work, but If someone knows how the js Map can perserve order please let me know (maybe just a linked list?).
function createMap(){
var obj = JSON.parse(bigStringRepresentingTheJSON);
return new Map(Object.entries(obj));
}
Looking at the profiler I see that both Maps take 917kb - how can that be? But Object (obj) from which they were made takes 786kb and 1 572kb - which is reasonable.
So I thought maybe Map holds a pointer to obj from which it was created, and thats why they don't differ in size? Then, I used the createMap function so that obj gets garbage collected. Only then, Map objects take 1 9kb and 2.3kb, which is to be expected.