哪个 Abc 类的对象使用更少的内存:Abc 类或还实现多个接口(如 Serialized 等)的 Abc 类?
我们正在优化大规模多线程 Java 应用程序的内存使用。
当我看到一些类不必要地实现了不需要的接口时,我遇到了上面的问题。
尽管我的直觉说没有任何实现的 Class 对象应该占用更少的内存。但是,我没有任何东西可以支持这一点。
有什么线索吗?
We are in middle of optimizing memory usage of a massively multithreaded Java application.
I ran into above question when I saw few classes unnecessarily implementing interfaces which is are not required.
Though my gut says the Class object without any implementation should take lesser memory. But, I don't have anything to back that up.
Any clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们谈论类实例,那么是的,实现更多接口的类将比未实现那么多接口的同一个类使用(稍微)更多的内存。不过,我怀疑您正在询问作为给定类的实例的对象。这些不会受到实现的接口数量的影响。实现的接口只会影响前面提到的类实例,而不影响类的实例。
If we're talking about Class instances, then yes, a Class implementing more interfaces would use (slightly) more memory than the same class not implementing as many interfaces. I suspect, though, that you're asking about objects that are instances of the given class. Those wouldn't be affected by the number of implemented interfaces. Implemented interfaces would only affect the aforementioned Class instances, not instances of a class.