Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7169517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:00:26+00:00 2026-05-28T15:00:26+00:00

How large, in bytes, is a boxed primitive like java.lang.Integer or java.lang.Character in Java?

  • 0

How large, in bytes, is a boxed primitive like java.lang.Integer or java.lang.Character in Java?

An int is 4 bytes, a typical pointer is also 4 byte (if not compressed by the JVM). Is the cost for an Integer (without caching) thus 4 bytes + 4 bytes = 8 bytes? Are there any more hidden fields within the box-object or additional overhead incurred regarding objects (i.e. is there a general cost for objects that I’m not aware of?).

I’m not interested in caching issues. I know that Integers within a certain range are cached by the JVM.

One could rephrase the question: What is the maximum factor to be multiplied on the amount of memory used for boxed values versus primitive values?

EDIT: I do understand that multiple implementations of the JVM exist. What is the typical cost in a typical 32-bit HotSpot Implementation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:00:27+00:00Added an answer on May 28, 2026 at 3:00 pm

    This is implementation defined, so there’s no specific answer. But I should be able to answer it for Hotspot.

    What you need to know is: Hotspot always aligns objects on 8byte boundaries. Furthermore there are 2 words overhead for each and every object. [1]

    If we put this together we get:

    32bit VM: 4byte integer + 2 words object header = 12bytes. That’s no multiple of 8 so as a result the cost for 1 integer is the next multiple of 8: 16byte.

    64bit VM: 4byte integer + 2 words = 20bytes. Rounding up again: 24byte size.

    The size of a reference obviously does not play into the size of an object itself, except if it has references to other objects which isn’t the case for a simple int wrapper. If it would, we’d have 4byte per reference for 32bit and 4byte for heaps <= 32gb with CompressedOops on modern JVMs (otherwise 8byte) for 64bit JVMs.

    [1] Interested people can look at the code in share/vm/oops/oop.hpp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a byte[] in Java which reports its length as 256 bytes which
my app print several line like: tcmalloc: large alloc 4294488064 bytes == 0x2b968d8000 @
In my C# application, I have a large struct (176 bytes) that is passed
I have a unit test where I have statically defined a quite large byte
I'm concatenating a large number of byte[] arrays in C#. If I were doing
I have a rather large SQL file which starts with the byte order marker
If I am creating a relatively large structure, how can I calculate the bytes
I'm using AESCryptoServiceProvider in C#/.Net Framework and I'm wondering how large, in bytes, the
I'm reading a large xml file using HttpURLConnection in java as follows. StringBuilder responseBuilder
I'm sending very large (64000 bytes) datagrams. I realize that the MTU is much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.