12 Replies Latest reply on Apr 28, 2003 5:49 AM by Vandenbroucke Johan

    memory leak ? ejb passivate / remove

    Vandenbroucke Johan Newbie

      Hello,

      We have now a web application running to sell tickets on WWW, its
      works fine except we must restart jboss every 3 days the machine because no more memory available.

      After a litle searching on the forums here , i found somsbody that says u must remove the ebj after using (myejb.remove() )

      I have implemented this , but it seems it never happens .

      Question 1: could the not remove be responsble for the memory consumption?

      Question 2: how can u forse a remove ?

      Greetings

      Johan

        • 1. Re: memory leak ? ejb passivate / remove
          Juha Lindfors Master

          what version of jboss? how much heap are you allocating to your JVM? stateless bean pool size?

          • 2. Re: memory leak ? ejb passivate / remove
            Vandenbroucke Johan Newbie

            Jboss 3.0.4 and Jboss 3.0.6 and now testing Jboss 3.2.0
            JVM 1.4.1

            How can i see the heap for JVM?

            How can i see the stateless bean pool size?


            Johan

            • 3. Re: memory leak ? ejb passivate / remove
              Juha Lindfors Master

              See the -Xmx option for your JVM. Set it to say -Xmx512m in your run script to use max 512 megs of memory.

              Default pool sizes are defined in the conf/standardjboss.xml, you can override these per bean in your jboss.xml, see the DTD for details.

              You're hitting the VM max heap limit. Calling remove() on a stateless session is a no-op. The ejbRemove() will be called when the container needs to remove the instance from the pool.

              Also, if you're using entities, check the cache size for standard entity config -- it is set to a rather large value. If you're still getting out of memory after max heap is set to 500+ megs you may want to check that. Chances are the memory is not running out because of your stateless bean instances but something they do in terms of resource allocation.




              • 4. Re: memory leak ? ejb passivate / remove
                Vandenbroucke Johan Newbie

                Hello,

                I never see the EJB-remove happens , i think thats the main problem
                of the memory leak.
                The Ejb i use connect a linux library (.so) with JNI , must i dos something special to Remove the EJB if i use JNI inside it?

                Ejb-code
                =======
                public void ejbCreate() {
                System.err.println("@@@ EJB-CREATE @@@");
                }
                public void ejbRemove() {
                System.err.println("@@@ EJB-REMOVE @@@");
                }

                Loging
                =======
                14:47:29,464 ERROR [STDERR] @@@ EJB-CREATE @@@
                14:47:29,509 INFO [STDOUT] ;Visitor;Host=127.0.0.1;IP=127.0.0.1
                14:47:30,167 ERROR [STDERR] ;SELECTED_ITEM=Elvis Presley 07/12/2003;IP=127.0.0.1;SESSION=6an9dgqrsghpq
                14:48:37,660 ERROR [STDERR] ;DESTROY=6an9dgqrsghpq

                • 5. Found one of the leaks
                  Vandenbroucke Johan Newbie

                  Hello,

                  One of the leaks was the not releasingof some strings in my JNI code.
                  I changed my code but i have still problems with memory leaks.

                  Is there a tooling so that i can see easy the JVM stack?

                  Johan

                  • 8. Re: Found one of the leaks
                    Vicky Kak Master

                    Hi,

                    As the main problem is suspected due to memory leak what i will suggest is to clean all the allocation in the Session Bean.If it is a Stateless then there is no problem but if it is a Stateful and if the logic i uing some allocation , as the Stateful it works on the concept of caching then possibility is that the resources used are allocated and are not realeased properly,I mean the ejbActivate() or ejbPassivate() not doing the proper clean up...
                    Also if the extented options like -Xms and -Xmx are used it is basically starting the JVM with more heap size but then if the leak is there then it can't be the proper solution. Ya if the leak is not there and there is more load then it seems to be the proper solution.

                    Regards
                    Vicky

                    • 9. Re: Found one of the leaks
                      Bernd Zeitler Expert

                      Hi,

                      ejbRemove() is not allways called. Read the EJB spec for more information (ch. 7.6.3). Does your log file show some exceptions? You could implement finalize() for your bean as fallback for cleaning up resources.

                      And btw, the spec even says you must not call native libraries from your EJB ;-)

                      Greetings,

                      Frito

                      • 10. strong weak and soft references
                        Vandenbroucke Johan Newbie

                        it looks we have problems with strong refrences (because using HashMap, LinkedList , ...)
                        So the strong references (that are added in the Maps, or linkedlist ) are never cleaned up (after investigate the mem and heap with jprofiler)

                        We have implemented Soft and weak reference, Weak doesn't work in our application. We lose to fast the data. Soft Reference seams to work, but in the docs they describes it is will be only cleared up when memory runs low. My fear is that garbage collector then cleared up all soft references, so we lose again the data of users that are busy.

                        Is there another method to solve this issue?


                        Johan

                        • 11. strong weak and soft references
                          Vandenbroucke Johan Newbie

                          it looks we have problems with strong refrences (because using HashMap, LinkedList , ...)
                          So the strong references (that are added in the Maps, or linkedlist ) are never cleaned up (after investigate the mem and heap with jprofiler)

                          We have implemented Soft and weak reference, Weak doesn't work in our application. We lose to fast the data. Soft Reference seams to work, but in the docs they describes it is will be only cleared up when memory runs low. My fear is that garbage collector then cleared up all soft references, so we lose again the data of users that are busy.

                          Is there another method to solve this issue?


                          Johan

                          • 12. Strong weak and soft references
                            Vandenbroucke Johan Newbie

                            Hello,

                            We have seen with Jprofiler that some of our objects are never cleaned up by the garbage collector. All these objects are part of a LinkedList or a HashMap. So we have problems wit Strong reference i guess.

                            We have implemented WeakReference (bad result , losing to fast our data)
                            and SoftReference. The soft reference seams to works. But the doc describes the GC only clean up if the memory runs low. My fear is that he then clears all the Weak References (so users that are busy on the site on that moment will have troubles)

                            Is there another solution?

                            Johan