1 Reply Latest reply on Feb 3, 2010 8:45 AM by megalodon

    Strategy for classpool = null clearing

    paulkeeble

      In the tutorial one of the noted problems is the memory usage climb with creating a lot of CtClass's etc that are all stored in the ClassPool. I am having trouble combining that advice with a javaagent implementation.

      The problem is really the order you see classes in and knowing when its safe to clear the pool. For instance say I have the following two classes:

      class Account {
      ...
      }
      
      Class SavingsAccount extends Account {
      ...
      }
      


      The javaagent will receive first the Account class, followed by the SavingsAccount. If you clear the pool after the Account class then SavingsAccount will see an a non enhanced class (which I can't do as I am adding constructors which the subclass will call).

      So the question is really what is the usual approach to this? So far I have tried the following:

      - Clearing every X times called, fails for obvious reasons
      - Clearing at the beginning of the program, fails because not all classes are necessarily loaded at that point

      I need something that some how mind reads the future calls! Any ideas?

        • 1. Re: Strategy for classpool = null clearing

          I don't have much experience in this but i follow the advice in the tutorial and

          use

          CtClass.detach() 

          for any class that I don't instrument.

           

          I also specify

               

          
          

          CtClass.doPruning = true.

           

          So far so good for me but I'm guessing I'll have to make better optimizations down the lane.