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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:02:46+00:00 2026-06-03T15:02:46+00:00

I have three array variables of a[dynamic], b[dynamic], c[dynamic] . They can be of

  • 0

I have three array variables of a[dynamic], b[dynamic], c[dynamic]. They can be of any size. I want to destroy one of the variables (e.g. a) as I won’t use the variable no longer.

  • 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-03T15:02:52+00:00Added an answer on June 3, 2026 at 3:02 pm

    You can indicate to the garbage collector that an array can be released by assigning null to it:

        int[] a = new int[someSize];
        int[] b = new int[someSize];
        ....
        // I no longer need 'a'
        a = null;
        // ... but I can still use 'b'
    

    However there are a number of things to note:

    • This does not free the space. Rather, it is making the array eligible to be freed by the garbage collector. The GC may not get around to freeing it for a long time.

    • In fact, the array is only eligible for garbage collection if it is not reachable. If you’ve assigned a reference to the array to another (still live) local variable, a field of a reachable object, and so on, the GC won’t reclaim it.

    • There is rarely any point in doing this (nulling variables) in real-life Java applications. It is normal practice to simply allow the variables go out of scope in the normal course of the computation1. You would only explicitly null a variable (or object field or array element) like that if the variable is not going to go out of scope for a long time AND it refers to a large array / object or network.

    • It is highly inadvisable to try to force the GC to run by calling System.gc() after assigning the null … or ever2. If the call has any affect at all, it is likely to be expensive. It is better to let the JVM schedule a GC at an optimal time.


    1 – Any reasonable JVM implementation will know that local variables go out of scope when a method exits. Whether the JVM tracks scopes at a finer granularity is implementation specific, and (to be honest) I do not know how JVMs handle this in practice.

    Note that just about anything is technically conformant to the JLS requirements …. provided that the GC does not delete reachable (i.e. non-garbage) objects. That includes a JVM that uses the Epsilon no-op GC, which never collects garbage and terminates the JVM when it runs out of space.

    2 – The only legitimate reasons are: 1) testing the behavior of GC related functionality; e.g. finalizers, reference queue processors, etc, or 2) avoiding harmful GC pauses in a real-time application; e.g. running the GC when changing "levels" in a real-time game.

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

Sidebar

Related Questions

I have three arrays, all the same size: xout % cell array xin %
I have two array and three button in segment control i want that when
hello every one i want to ask that i have read that we can
I have a array with a variable amount of values. Is there a more
I have three colors in an array, array('blue', 'red', 'green') , and in my
I a having a little trouble with vector or array operations. I have three
i am using visual studio 2010. i have a three dimensional structure array which,
i have a three dimensional bit table array as bit_table[dim1][100][200]; The second and third
I have a union type of array of three integers (4 bytes each), a
I have the following three arrays and need to create a new two-dimensional array

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.