aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Maximum size of Java Object" Watch "Maximum size of Java Object" New topic
Author

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
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18138
    
  39

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.

Henry


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: 13884
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maximum size of Java Object
 
Similar Threads
Worrying about the documentation
max size of a string
maximum size of the session object
Java BufferedImage - OutOfMemoryError
Tomcat and Optimizeit throwing Out of memory error