• Post Reply Bookmark Topic Watch Topic
  • New Topic

Number of objects created  RSS feed

 
Elizabeth King
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a stand alone Java application to do a simulation.
Is there a way to get the total number of the objects which are
created in the application? I'm using Java 5. Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elizabeth,
If you are looking for the # objects of a specific class you control, you could add a line to the constructor to increment a static field each time an object is created. If this is more general, you could use a profiler which will track the number of objects/memory across the board.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!