Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird measurements #7

Open
ittayd opened this issue Dec 14, 2015 · 1 comment
Open

Weird measurements #7

ittayd opened this issue Dec 14, 2015 · 1 comment

Comments

@ittayd
Copy link

ittayd commented Dec 14, 2015

(sorry the example is in Scala)

scala> case class Person(name: String, surname: String)
defined class Person

scala> objectexplorer.MemoryMeasurer.measureBytes(Person("", ""))
res1: Long = 64

scala> objectexplorer.MemoryMeasurer.measureBytes(Person("h", ""))
res2: Long = 112

scala> objectexplorer.MemoryMeasurer.measureBytes(Person("h", "h"))
res3: Long = 72

In the first line I declare a class with two properties. In the second I measure the size of an object of that class that is instantiated with 2 empty strings. In the third, an object with 1 character string and empty string. The size is indeed larger. Now I try with an object of two such strings. The size becomes less?

@vijaykiran
Copy link

I think this behaviour is reasonable since the strings are interned - hence "" and "" are the same string won't take double the memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants