案例类内存消耗

时间:2013-06-17 15:50:28

标签: scala memory-management

我有定义某些实体结构的代码,例如:

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

我有以下实体代码:

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

每个实体是否会占用额外的内存来存储它的entityDefinition实例?我打算保持EntityDefinitions的数量非常低,但每个都会占用很大的数量。

所以问题是是为实体保留这个结构,还是实现某种类型的Reference,它会根据需要从缓存中获取实体定义?

1 个答案:

答案 0 :(得分:4)

如果您共享实体定义,那么您只需为每个Entity计算一个对象引用。对象引用的大小为specified by the JVM

相关问题