how do i get instance count of an java object?

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?
LVL 1
sharath_kulalAsked:
Who is Participating?
 
vk33Connect With a Mentor Commented:
afaik, it's the matter of specific JVM implementation. You can only manipulate stored links.
0
 
objectsConnect With a Mentor Commented:
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
 
jimmackConnect With a Mentor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
TimYatesCommented:
I think they meant reference count ;-)
0
 
grim_toasterConnect With a Mentor Commented:
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
 
TimYatesConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.