3 Replies Latest reply: May 21, 2012 3:43 PM by 938491 RSS

    How to get all instatiated objects

      I have a very simple question to ask.
      How to get all the objects which have been instantiated during run time through a simple java program? ..Please help.
        • 1. Re: How to get all instatiated objects
          You can't.

          You can do it via a very complex Java program that uses the debugger APIs. I think.
          • 2. Re: How to get all instatiated objects
            What is it that you're trying to accomplish?

            What problem is it that you have, where you think the solution is to get a list of every instantiated object?

            What are you planning to do with that list?

            Even a very small, short-lived program can easily create hundreds or thousands of objects during its lifetime, so it's unlikely that a complete list will be of any practical use.

            If you want to observe, for example, which objects are consuming the majority of your memory because you're trying to reduce the memory footprint, you could use a profiler, such as JProbe, JProfiler, OptimizeIt, or VisualVM.
            • 3. Re: How to get all instatiated objects
              Actually I have a Tool which checks for a particular type of object and takes some action on it. I want to invoke that tool via my java program on run time and check for that particular type of object. That's why I want a complete list of objects through which I will iterate and invoke my tool if that particular object type is found.