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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:13:49+00:00 2026-06-06T20:13:49+00:00

I have a static map in my application which populates when I click on

  • 0

I have a static map in my application which populates when I click on a link.
After that it makes lots of objects and store them. Now I have a link which will clear this Map.

Here is my code.

Hello1 hello1 = new Hello1();
hello1.setHello("Helllollo1");
Hello hello = new Hello();
hello.setHello1(hello1);
hello.setHello("Hellollo");
setMap("1", (Object)hello);

Hello1 hello2 = new Hello1();
hello2.setHello("Helllollo1");
Hello helo = new Hello();
helo.setHello1(hello2);
helo.setHello("Hellollo");
setMap("2", (Object)helo);

Hello1 hello3 = new Hello1();
hello2.setHello("Helllollo1");
Hello helo1 = new Hello();
helo1.setHello1(hello3);
helo1.setHello("Hellollo");
setMap("3", (Object)helo1); 

Now I have a method removeMap which works as below

public static void removeMap(String key){

        if(map.containsKey(key)){

            map.remove(key);
        }   
    }

So when I call this method for a single key after adding above three object, is that object Garbage Collected or not?

  • 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-06T20:13:51+00:00Added an answer on June 6, 2026 at 8:13 pm

    Yes, after the map is cleared, the objects which were referenced from it will become eligible for garbage collection if there are no other strong references to them.

    Note that removing the entry from the map won’t immediately cause garbage collection – it just means the map will no longer be preventing the object from being garbage collected.

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

Sidebar

Related Questions

I have a static map that is a private data member. How do I
I have a service that contains a map: static Map cargosMap = ['1':'item1','2':'item 2','3':'item
I have a HashMap<String,String> and there is a static method which returns this map
I have a Rails application that uses a static_pages controller to render static pages
I have a few static unordered_maps in my application that I would like to
In my application, I already have some static overlays on the map, and one
I have intialized Hash map inside static block, I need to access the hashmap
I have static method which returns me as it's name says data from domain
Suppose I have static ip in a subnet that has DHCP server. If i
Is it possible or makes sense to have static dynamic variables on a class,

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.