Solved

how do i get instance count of an java object?

Posted on 2003-12-01
8
1,554 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:TimYates
Comment Utility
I think they meant reference count ;-)
0
 
LVL 7

Assisted Solution

by:grim_toaster
grim_toaster earned 20 total points
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

772 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

10 Experts available now in Live!

Get 1:1 Help Now