Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Misc > Re: Counting Cl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 967 of 1011
Post > Topic >>

Re: Counting Class Instantiations

by Miss Elaine Eos <Misc@[EMAIL PROTECTED] > Jan 13, 2008 at 01:48 AM

In article <hb0o55-hie.ln1@[EMAIL PROTECTED]
>,
 Luc The Perverse <ataylor_no_spa_am@[EMAIL PROTECTED]
> wrote:

> I was wondering if Java has a built in feature that could be easily 
> enabled to count unique class instantiations.

I don't know if there's anything built in, but you could always make 
everything derive from:

class DebugObject extends Object //    NOT checked for syntax!
{
   private  static   int   objectCount = 0;

   DebugObject ()
   {
      super();
      ++objectCount;
   }

   protected void finalize()
   {
      objectCount--;
      super.finalize();
   }

   public   int   objectCount()
   {
      return (objectCount);
   }
}


If you want to simplify switching back & forth, you can also have:

class JavaObject  extends Object
{
   JavaObject()
   {
      super();
   }
}


Then it's pretty simple to do replace-all in your project.  (If you 
replace-all to "Object", it can get trickier to go back to DebugObject, 
depending on the rest of your project.)

If *ONLY* javac had a preprocessor!  ;)

-- 
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.
 




 2 Posts in Topic:
Counting Class Instantiations
Luc The Perverse <atay  2008-01-12 15:50:40 
Re: Counting Class Instantiations
Miss Elaine Eos <Misc@  2008-01-13 01:48:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 8:59:46 CDT 2008.