Apparently, null is not a constant Coming up next: Profilers
Jan 17

Following Bharath Ganesh’s post I copied his code piece and tried it. The result was 1.

“Great”, I thought, “The problem must be in his JVM, whatever that is.”

Just for a small test, I added another line, s2 = null, right before the call to the garbage collector. The result was still 1.

First null wasn’t a constant, and now this!

Share/Save/Bookmark

2 Responses to “Problems with WeakHashMap”

  1. Avah Says:

    Upodate: All is well, there is order in the universe. I added a Thread.sleep(1000) after the call to the Systen.gc(), thinking it might be asynchronious.

    It was. And the result actually was 0, just as Bharath Ganesh says.

    Weird.

  2. Avah Says:

    Which reminds me. The JavaDoc specifies:

    When control returns from the method call, the virtual machine has made its best effort to recycle all discarded objects.

    So why is it asynchronious?

Leave a Reply

Chaotic Java is Digg proof thanks to caching by WP Super Cache!