1 Reply Latest reply: Jun 2, 2011 12:04 PM by 796440 RSS

    Static reference varible not getting garbagecollected on Undeployment

    866115
      I have a simple Util which have a static reference varibale.
      static B b=new B(); reference in Util and has been initilized in init() servlet.

      On undeployment i could see b not get garbage collected and still there in heap.

      It is beaving similarly in timcat 7 and weblogic 10.2 too.Can we configure this behaviour?

      thanks
      fiji
        • 1. Re: Static reference varible not getting garbagecollected on Undeployment
          796440
          First, variables don't get GCed. Objects do. The only way a variable gets GCed is when the object that contains it does. I see two possible scenarios here, and since you haven't provided much information, I have no idea which one reflects your situation, or if neither of them does.

          Scenario 1) You are observing that the object pointed to by b is not being GCed. This means one of two things. Either there's some other reachable reference to that object still hanging around, or GC just hasn't got around to or had a need to reclaim that object yet. Just because an object can be GCed, that doesn't tell you anything about when or even if it will be. The only guarantee is that an attempt will be made to reclaim memory if it is necessary in order to free up space for an existing request.

          Scenario 2) You are observing that variable b itself is not being GCed. Since b is static, this can only mean that the class that defines b is not being GCed. This is not surprising, as a class can only be GCed when the classloader that loaded it is GCed, and that only happens in very specific circumstances. Simply undeploying the servlet may not necessarily be enough to get the class unloaded.

          In either case, is there an actual problem here that you're trying to diagnose and solve? Or are you just trying to educate yourself about the mechanics of GC?