Solved

how do i get instance count of an java object?

Posted on 2003-12-01
8
1,565 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 70
login form jsp example 2 50
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) 1 58
Chrome and Firefox Java 5 67
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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.

756 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