abatyuk
abatyuk

Reputation: 1342

Case classes memory consumption

I have the code that defines some entity structure, for example:

case class EntityDefinition(id: UUID,
                            name: String,
                            propertyDefinitions: Map[String, PropertyDefinition] = Map.empty[String, PropertyDefinition])

And i have the following code for entity:

case class Entity(entityDefinition: EntityDefinition, 
                  id: UUID, key: String, 
                  properties: Map[String, Property[Any]])

Will each entity take extra memory for storing it's entityDefinition instance? I intend to keep the number of EntityDefinitions very low, but each will occupy significant size.

So the question is whether to keep this structure for an entity, or to implement some kind of Reference that would get the entity definition from the cache on demand?

Upvotes: 0

Views: 1201

Answers (1)

0__
0__

Reputation: 67330

If you share the entity definitions, then you only need to calculate one object reference per Entity for them. The size of an object reference is specified by the JVM

Upvotes: 4

Related Questions