sizeof icon indicating copy to clipboard operation
sizeof copied to clipboard

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

Open rebeccapeltz opened this issue 6 years ago • 2 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.

rebeccapeltz avatar Apr 29 '18 22:04 rebeccapeltz

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

Pyrolistical avatar Apr 30 '18 18:04 Pyrolistical

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.

miktam avatar Apr 30 '18 19:04 miktam