Is there a way to find out the memory/size occupied by an object in scala? Thanks in advance for replying me.
Scala runs on the JVM, the runtime system which backs Java. A Scala object is compiled into a JVM object at runtime, and is indistinguishable from a Java object at runtime. See for example the "Scala in a Nutshell" intro at https://www.scala-lang.org/ :
SEAMLESS JAVA INTEROP
Scala runs on the JVM, so Java and Scala stacks can be freely mixed for totally seamless integration.
...
Scala classes are ultimately JVM classes. You can create Java objects, call their methods and inherit from Java classes transparently from Scala. Similarly, Java code can reference Scala classes and objects.
So for the purposes of this question, any Java answers are equally applicable to Scala.
Please refer to
- In Java, what is the best way to determine the size of an object?
- What is the memory consumption of an object in Java?
(Unless you are referring to non-standard Scala runtimes like Scala.js? In that case, you should look for answers that apply to the underlying runtime, like How to get the size of a JavaScript object? )
© 2022 - 2024 — McMap. All rights reserved.