Solved

how do i get instance count of an java object?

Posted on 2003-12-01
8
1,556 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
8 Comments
 
LVL 4

Accepted Solution

by:
vk33 earned 20 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 20 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 20 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 20 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 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network + 7 80
java. non-English characters encoding problem. intellij idea 3 74
print map entry 34 55
why cannot we forward request once the response is committed 2 33
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now