• Post Reply Bookmark Topic Watch Topic
  • New Topic

Knowing number of instances of an object?  RSS feed

 
Adil Fulara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering how does one find how many instance of a object have been created during a running program.

thank you.

~Adil.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generally speaking, i don't think you can.

If you have written the object, you could use a static variable and put code in the constructor to increment each time a new one is created - but then you have a problem as you don't really have any way to decrement it.

sure, you could write a destroy() method that would do just that, but you can't guarantee it will be called properly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!