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

  • Home
  • SEARCH
  • 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 6345871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:54:24+00:00 2026-05-24T20:54:24+00:00

Does anyone have any information on what optimisations (I realise this is implementation specific)

  • 0

Does anyone have any information on what optimisations (I realise this is implementation specific) most JVMs will do when confronted with a final object? In particular, an array of final objects in Java? For example:

final class A { }
A myArray[] = new A[10];

If the class “A” is final then it can have no subclasses, so it seems like it would be possible to allocate (not calling constructors) the entire array (i.e. malloc(sizeof(A)*10)) and save on garbage collection/book keeping.

  • 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-24T20:54:25+00:00Added an answer on May 24, 2026 at 8:54 pm

    I severely doubt any JVM would bother to do that. In part because it would probably create extra book keeping. Any instance held both in the array and else where would have to dual modified to keep in line with the rules of the JVM.

    eg.

    final class A {
        String value = "default";
    }
    
    A instance = new A();
    A[] array = new A[] {instance};
    instance.value = "another value";
    assert instance == array[0];
    assert instance.value == array[0].value;
    

    The implementation you suggest would force a copy of instance to be created when the array is created, thus forcing the JVM to remember to change the contents of value whenever it was changed in the other instance of A.


    In response to your comment:

    That’s an interesting idea and would work to a certain extent. However, your idea will wreck garbage collector performance. The reason for this is that the best JVMs don’t use reference counting. The best JVMs use a moving garbage collector. This technique traces from all root nodes (eg. Threads) to see what objects are referenced. All objects in the reference chain are moved into a contiguous block. Any memory outside of this block is considered free. No calls to dealloc or finalise or anything. This technique is VERY fast (in part due to the high “infant mortality” of objects in GCed languages). What’s more is that this technique doesn’t have to bother checking for circular references.

    Back to the point: when the array drops out of scope the JVM will have to check if there are any other references to elements of the array and malloc new space for these objects before it can free up the memory of the array. This prevents the use of a “moving garbage collector” and we have to go back to inefficient GC techniques like reference counting. So whilst you idea seems good at first glance (and only for a certain edge case), it prevents other GC strategies that can be more widely applied and provide much greater efficiency savings.

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

Sidebar

Related Questions

Does anyone have any information on this? I'm currently running Visual Studio Team System
Does anyone have any information about getting the current versions of ASP.NET MVC (Preview
DOes anyone have any good information with regards to when to log, I was
Does anyone have any useful advice/links to information about working with mp3 files in
Does anyone have any good sources of information of using NHibernate with Sql Azure
Does anyone have any examples or resources where i might find information on scrolling
Does anyone have any tips for dealing with ConstraintExceptions thrown by XSD datasets? This
Does anyone have any information on the performance characteristics of Protocol Buffers versus BSON
Does anyone have any information comparing performance characteristics of different ConnectionPool implementations? Background: I
Does anyone have any information on how state is managed in Azure when you

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.