• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Count Objects !

 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can I count how many instance/objects are created on heap towards operations on String. e.g



Is there any generalized/common logic/tip to count it?

In advance, Thank you!
 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best method to get number of instances created of a specific class is - , make a static 'count' varible and increment it in constructor call, so that you can access that count method through a static method like "static int getCount()" to return the no of objects created ..

Now as per Java api , there is no such method in String class, and String class is "final" , you cant create your own .

And other way to do this , might go from complier and memory management programming or ask sun .
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only definitive solution would be to run the code through a profiler.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use AspectJ to weave code into the String constructors.
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Presently I'm using Netbean 5 is there any tool for it as AspectJ. By the way what is the AspectJ.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AspectJ on Wikipedia and Eclipse.org
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob,

I already had a glance on both of these site before posted the reply. However I' was unable to have the utility of this tool.

Can I have the gist of this tool, to proceed in a right way, feasibly in NetBean 5 IDE.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't help you any further; I haven't used it since late 2003 when I was investigating it for my master's thesis.

Now I don't know about integration in Netbeans, but with its documentation you should be able to run it from the command line.
[ June 01, 2008: Message edited by: Rob Prime ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic