Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do i get instance count of an java object?

Posted on 2003-12-01
8
Medium Priority
?
1,582 Views
Last Modified: 2012-06-27
how do i get instance count of an object.
since i want to free memory. i can set an reference to null.
but if there are other references to the same object garbage collector
won't free the memory. i want to explicitly set all references to that
object to null. how do i do that?
0
Comment
Question by:sharath_kulal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Accepted Solution

by:
vk33 earned 80 total points
ID: 9848820
afaik, it's the matter of specific JVM implementation. You can only manipulate stored links.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 80 total points
ID: 9848821
you can't. best you can is (and all you really need to do) is make sure you set any references to null when they are no longer needed.
0
 
LVL 15

Assisted Solution

by:jimmack
jimmack earned 80 total points
ID: 9848830
Besides that, in the circumstances you describe, an instance count wouldn't help.  Multiple references to a single object would not affect a count of instances.
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 35

Expert Comment

by:TimYates
ID: 9848909
I think they meant reference count ;-)
0
 
LVL 7

Assisted Solution

by:grim_toaster
grim_toaster earned 80 total points
ID: 9848919
If you're really concerned about memory, I would suggest getting hold of a memory profiler.  One that I would recommend is JProbe (you can download a trial version), but the only problem with it is that it is not a free product!

http://java.quest.com/jprobe/
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 80 total points
ID: 9848931
OptimizeIt is an ok profiler too :-)

You do need to do some investigation as to whether something is a leak, or normal behaviour, as with GC being non-deterministic, it can get a bit tricky ;-)

Memory profiling was so much easier with malloc, calloc, and free ;-)

http://www.borland.com/optimizeit/
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question