File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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: 24189

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: 19725

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: 14741

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:
subject: Maximum size of Java Object