Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1591
  • Last Modified:

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?
0
sharath_kulal
Asked:
sharath_kulal
5 Solutions
 
vk33Commented:
afaik, it's the matter of specific JVM implementation. You can only manipulate stored links.
0
 
objectsCommented:
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
 
jimmackCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TimYatesCommented:
I think they meant reference count ;-)
0
 
grim_toasterCommented:
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
 
TimYatesCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now