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 7802761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:21:08+00:00 2026-06-02T01:21:08+00:00

I am currently designing a data structure in which I’m trying to keep memory

  • 0

I am currently designing a data structure in which I’m trying to keep memory consumption to a minimum. I have a few instance variables that may be null depending on the placement of the Node in the Trie. I started going down the path of creating separate classes (one that has the instance variable and one that doesn’t) so that I won’t waste tons of space with null references… but then I started to wonder how the jvm works. Does it still eat up the full 8 bytes (assuming x64 arch) if the object reference is null or does it have a more optimal way to store a null reference?

  • 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-06-02T01:21:10+00:00Added an answer on June 2, 2026 at 1:21 am

    I’m almost sure JVMs will use as much space for a null reference as for any other one. If you have an object with say 3 reference fields, and you null out the one in the middle, I don’t think any virtual machine would be able to move the 3rd one and save the 4 or 8 bytes (and then when you changed the null to something else, it would have to move stuff around again). If if this was technically feasible, it would not be worth it – the extra computational cost and code complexity would kill any potential gains. Also, partly due to C heritage, on most machines a pointer equal bit-wise to 0 works as a NULL at a very low level, so the null reference has a rather obvious representation.

    On Oracle/Sun JDK you can use -XX:+UseCompressedOops command line argument to make references 4 bytes instead of 8 on 64-bit if your heap is smaller than 16 GB (regardless of whether the reference is null or not).

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

Sidebar

Related Questions

I am currently designing a correlation engine in java which is extracting data from
I'm currently designing a small application in which I have: - 1 menu (graphic
I'm currently designing an app that pulls map data from a service and renders
I am currently designing a class library that will provide data to a web
I'm currently designing an application which I will ultimately want to move to Windows
I am currently designing a public-facing C++ API for a product which will require
I'm currently designing a smart client app (WPF) which needs to operate in an
I am currently designing a focused webcrawler. I have it tested with some websites
I'm currently designing a object structure for a game, and the most natural organization
I am currently designing a web application where I will have customers signing up

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.