miktam / sizeof

Get size of a JavaScript object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Counting the size of same object twice if referenced twice in DS

rebeccapeltz opened this issue · comments

I have a data structure that encapsulates the same element twice - once in an array and once in an object to provide both direct access and iteration of a set of data. I ran this function on it and it appears to report double the size. I think this algorithm may not take into account the fact that is is counting the size of the same object twice. You can see this DS here: https://github.com/rebeccapeltz/map-list.

hmm, i don't know if this should even be considered a bug. if you JSON.stringify it, it would show up twice

from the perspective of a person who wants to get an estimated size in Bytes - I would not count it twice, by maybe would count only a reference.
but from the perspective of how much memory will be consumed when printing (take @Pyrolistical example with the stringify) - current implementation is good enough.