8 Replies Latest reply on Sep 16, 2010 5:22 AM by icarus1111

    Leaking or not

    icarus1111

      Hi,



      I'm having difficulties with the Login servlet example which can be found in the manual 15.3 Calling a bean from a servlet.
      When I run this example with a profiler I see that for each servlet request one org.jboss.weld.resolution.ResolvableBuilder$ResolvableImpl and one org.jboss.weld.resolution.TypeSafeResolver$Key instance is created. However, when I force the Garbage Collector to cleanup these items, they won't be cleaned up after all. Am I doing something wrong? In our application we have a simular situation which leads eventually to an OufOfMemoryError.
      I'm using Glassfish 3.0.1 (build 22) with WELD-000900 1.0.1 (SP3).


      Hope someone can help me out.


      Regards,
      Ramon

        • 1. Re: Leaking or not
          swd847

          Thanks for reporting this, there is a leak.


          The fix should be merged into trunk in the next few days. If you want it right now it is available at http://github.com/swd847/core/tree/WELD-681

          • 2. Re: Leaking or not
            icarus1111

            That's great!
            However, we are using Glassfish 3.0.1, which (AFAIK) doesn't support Weld 1.1 beta (yet).
            Do you think it is safe that I patch Weld 1.0.1 by applying the Weld 1.1 beta fix modifications to the Weld 1.0.1 sources?


            Regards,
            Ramon

            • 3. Re: Leaking or not
              swd847

              I think that should be fine, all that is required is to fix the equals and hashcode method on TypeSafeResolver.Key


              • 4. Re: Leaking or not
                icarus1111

                It seems that it is bit too complex for me to fix it in 1.0.1. Stuart, maybe you can help me out? This is the TypeSafeResolver.equals implementation in 1.0.1:




                      @Override
                      public boolean equals(Object obj)
                      {
                         if (obj instanceof Resolvable)
                         {
                            Resolvable that = (Resolvable) obj;
                            return this.getResolvable().getTypes().equals(that.getTypes()) && this.getResolvable().getQualifiers().equals(that.getQualifiers());
                         }
                         else
                         {
                            return false;
                         }
                      }





                ...and the TypeSafeResolver.hashcode implementation:



                      @Override
                      public int hashCode()
                      {
                         int result = 17;
                         result = 31 * result + this.getResolvable().getTypes().hashCode();
                         result = 31 * result + this.getResolvable().getQualifiers().hashCode();
                         return result;
                      }





                I cannot find a clear match with the current beta code. Maybe you can give me some pointers how to patch this code?


                Regards,
                Ramon

                • 5. Re: Leaking or not
                  swd847

                  I think it is probably this bit:


                  @Override
                        public boolean equals(Object obj)
                        {
                           if (obj instanceof Resolvable)
                           {
                              Resolvable that = (Resolvable) obj;
                              return this.getResolvable().getTypeClosure().equals(that.getTypeClosure()) && this.getResolvable().getQualifiers().equals(that.getQualifiers());
                           }
                           else
                           {
                              return false;
                           }
                        }
                  



                  should be something like:


                  @Override
                        public boolean equals(Object obj)
                        {
                           if (obj instanceof Key)
                           {
                              Key that = (Key) obj;
                              return this.getResolvable().getTypeClosure().equals(that.getResolvable().getTypeClosure()) && this.getResolvable().getQualifiers().equals(that.getResolvable().getQualifiers());
                           }
                           else
                           {
                              return false;
                           }
                        }
                  

                  • 6. Re: Leaking or not
                    icarus1111

                    Great!


                    So no hashcode modifications needed?
                    Resolvable.getTypeClosure() is not defined in 1.0.1, should I replace it with getTypes?


                    Thanks a lot,
                    Ramon

                    • 7. Re: Leaking or not
                      swd847

                      I think the hash code is fine in that version, and you should replace getTypeClosure() with getTypes().

                      • 8. Re: Leaking or not
                        icarus1111

                        It looks like the leak is gone, Stuart, thanks a lot!


                        So, for those interested in this fix for Weld 1.0.1: replace TypeSafeResolver.Key.equals(Object obj) with:


                              public boolean equals(Object obj)
                              {
                                 if (obj instanceof Key)
                                 {
                                    Key that = (Key) obj;
                                    return this.getResolvable().getTypes().equals(that.getResolvable().getTypes()) && this.getResolvable().getQualifiers().equals(that.getResolvable().getQualifiers());
                                 }
                                 else
                                 {
                                    return false;
                                 }
                              }