jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Maximum size of Java Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Maximum size of Java Object" Watch "Maximum size of Java Object" New topic

Maximum size of Java Object

victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Is it true that maximum size of a Java Object is 2 giga bytes ?

What if object A contains another object B ?
Is the size of B included in the size of A ?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

The largest positive int is 2^31 -- i.e., about 2 billion . That places a number of limits on Java objects and code, but really, these are not very significant. What possible use could you have for a 2GB object, anyway? Aside from an array, I can't even conceive of how you'd create one.

To answer your question: that limit affects a single object, not a chain of object references. Each object has its own limit..

[Jess in Action][AskingGoodQuestions]
Henry Wong

Joined: Sep 28, 2004
Posts: 20514

Is the size of B included in the size of A ?

Basically, the reference to B is included in the size of A. So, for each object that your object contains, your object will be 4 bytes (8 bytes for 64 bit JVMs) larger.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15080

Note that there is no theoretical limit to the size of a Java object - the limit is determined by the particular implementation of the Java specification that you're using.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link: http://aspose.com/file-tools
subject: Maximum size of Java Object
It's not a secret anymore!