aspose file tools*
The moose likes Beginning Java and the fly likes Count Objects ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Count Objects !" Watch "Count Objects !" New topic
Author

Count Objects !

Prathamesh Gaddam
Ranch Hand

Joined: Feb 18, 2008
Posts: 58
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 .


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The only definitive solution would be to run the code through a profiler.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Or use AspectJ to weave code into the String constructors.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Prathamesh Gaddam
Ranch Hand

Joined: Feb 18, 2008
Posts: 58
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

AspectJ on Wikipedia and Eclipse.org
Prathamesh Gaddam
Ranch Hand

Joined: Feb 18, 2008
Posts: 58
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Count Objects !