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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:15:48+00:00 2026-06-05T15:15:48+00:00

Say I have classes class A{ //code for class A } class B{ //code

  • 0

Say I have classes

class A{
  //code for class A
}


class B{
  //code for class B
}

class A{
  public static void main(String a[]){
    //Initialize m instances of A and n instances of B and store each in arrays
    //Equate any arbit index in the array to null
  }
}

In this scenario, my main goal is to find all active instances of classes A and B in the memory at any point.

I suppose it must be possible using a debugger.

However, due to some reason (the reason being beyond the scope of the question), I am required to get the instances from within the code itself. Thus, i need a function like

public void getAllActiveInstances(){
  //Print values
}

Edit: I don’t need instances to operate over them. I just need to know whether they exist or not. This is mainly for debugging purposes.
If this is not possible then kindly explain how to do the same using debuggers.

  • 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-05T15:15:49+00:00Added an answer on June 5, 2026 at 3:15 pm

    The short answer is no, you should not be looking inside of memory at any time with java.

    The long answer is, if there was any way of accessing an object after GC has collected it, then you are violating the GC’s principal of only collecting things that cannot be reached in any way by the executing code. Garbage collected memory is freed and returned to the program to do anything it wants with it. This means if you’ve GC’d an object A, java is allowed to write any number of things into that location, destroying the “A-ness” of that block of memory. Attempting to read an object B that is now stored in that memory block and pretending it’s an A will cause all sorts of problems.

    Going forward: To keep track of all the classes you’ve created, I would suggest modifying the class itself. Your class can have a static container (like a HashMap), and the constructor adds the constructed class to the HashMap. However, note that because you are hanging onto references to all of your created object, Garbage collect will never collect those objects and free up that memory.

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

Sidebar

Related Questions

Let's say we have these two classes: public class Base { public static int
Let's say I have the following classes : public class MyProductCode { private String
So lets say I have these classes: public class Person { public string Name
Newbie question. I have two c# classes - a code class (say, CodeClass) and
Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1();
Say you have two classes, order and customer: public class Customer{ public int CustomerId
Say I have the following three classes/interfaces: public interface IImportViewModel { } public class
I have the following code with private static members. All of these classes say
Lets say I have a two classes like this: public class LocalResources { public
Lets say I have these classes: class Foo { public $_data; public function addObject($obj)

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.