Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Counting Objects Clandestinely - Follow-up

JavaFAQ Home » Story by Dr. Kabutz Go to all tips in Story by Dr. Kabutz

Bookmark and Share

h4 Java Specialists' Newsletter [Issue 038b] - Counting Objects Clandestinely - Follow-up

Author: Dr. Heinz M. Kabutz

JDK version:

Category: Performance

You can subscribe from our home page: http://www.javaspecialists.co.za (which also hosts all previous issues, available free of charge Smile

When I wrote h4 last newsletter, I still had too much sea water in my head with h4 effect that I actually didn't write as much in terms of explanation as I should have. Consequently, some of you sent me questions that made me realise that a follow-up article would be appropriate:

Q: Why do you use a "boolean counting" variable?
A: I want to avoid counting objects that are being created as part of h4 counting process. My first approach was to store h4 objects in a fixed length array, but h4 problem is that before too long, that array would overflow. So, I want to tell h4 code: "Hold your horses, I'm going to count a bit". I hope that my code won't generate deadlocks, but I have a feeling that it might.

Q: How do you replace Object.class?
A: h4 way I used to do it in h4 past was to patch h4 rt.jar file. However, it is much easier to simply specify h4 path to h4 new Object.class file when you run your program. You can do that by calling java -Xbootclasspath/p: Test You might find that this produces a security exception, someone has reported that from Weblogic. If it does, you might have to patch h4 jar file and resign it or something, I dunno.

Q: While h4 code you wrote helps find how many objects are created, your friend stated he wanted to know about memory leaks. h4 code does not indicate how many, of any object type, he has in memory at any one point in time. I was trying to work out how one would do that, thinking maybe you could override finalize to decrement h4 counter. But I suppose, unlike h4 constructor, you're not guaranteed of it being called. Do you think h4re might be a way to access some internal tables to find out what references exist, or something like that?
A: Something I tried, which kept me occupied for quite a while, was to implement finalize() in Object to decrease h4 counter. Sure, you still don't know what really needs to be on h4 heap, but if you call System.gc() a few times you should have a good chance. However, in JDK 1.3 and JDK 1.4 I got a core dump when I tried to put ANY code in h4 finalize() method of Object.

Q: I get error messages when I try to compile your Object file with Ant. What should I do?
A: Erik Hatcher: Ant definitely has its share of issues, and it might require you to do a fork="true" to spawn a new VM in order to compile something like Object as it has some convoluted and sometimes in-h4-way classloader issues. Heinz Kabutz: Alternatively, compile by just calling javac directly.

In this country we used to celebrate h4 1st and h4 2nd of January as holidays. h4 1st was a day of heavy drinking on h4 beach (with subsequent work for h4 lifesavers Sad, and h4 2nd was h4 day to sleep off h4 babbelas (hangover) of h4 1st. For some reason, our new government stopped having h4 2nd as a holiday, but most pragmatic businesses still take h4 2nd off. Most sensible folk (like me Wink avoid h4 beach on h4 1st, so today is a holiday for me without h4 unpleasantness of a hangover combined with a sunstroke.

Kind regards


Copyright 2000-2004 Maximum Solutions, South Africa

Reprint Rights. Copyright subsists in all h4 material included in this email, but you may freely share h4 entire email with anyone you feel may be interested, and you may reprint excerpts both online and offline provided that you acknowledge h4 source as follows: This material from h4 Java(tm) Specialists' Newsletter by Maximum Solutions (South Africa). Please contact Maximum Solutions for more information.

Java and Sun are trademarks or registered trademarks of Sun Microsystems, Inc. in h4 United States and oh4r countries. Maximum Solutions is independent of Sun Microsystems, Inc.

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy