5 Replies Latest reply on Jul 30, 2003 3:05 AM by Juha Lindfors

    Out of memory exception ....

    wayyoung Newbie

      I'm using Kodo to persist my object. When I persist a
      lot of object in one transaction (in on method), the out of memory excetpion happened when the trasaction tend to commit. I'm using JBoss 3.2.1 with oracle 8. Is there any sugesstion to solve this problem??
      Thanks a lot!!

        • 1. Re: Out of memory exception ....
          Juha Lindfors Master

          Set a larger physical heap size for your JVM (-Xmx) ? If it is Kodo (?) using up all the heap then there isn't much you can do from the JBoss side.

          -- Juha

          • 2. Re: Out of memory exception ....
            wayyoung Newbie

            Thax for your reply. But I think the problem is from JBoss. Following is my code (In concept):

            UserTransaction trans=new InitialContext().lookup(...)....;
            trans.begin();
            PersistenceManager pm=new InitialContext().lookup(...)....;

            for(int i=0;i<10000;i++){
            MyObject x=new MyObject();
            x.setValue(value);
            ...
            ...
            ...
            pm.makePersistence(x);

            }
            trans.commit();
            System.out.println("complete");

            The code will run without any warning. The the "complete" string will appear. But after a few seconds, JBoss will throw the OutOfMemory Exception.
            There will be no problem if I change the code to the following:

            UserTransaction trans=new InitialContext().lookup(...)....;
            trans.begin();
            PersistenceManager pm=new InitialContext().lookup(...)....;
            int count=0;
            for(int i=0;i<10000;i++){
            MyObject x=new MyObject();
            x.setValue(value);
            ...
            ...
            ...
            pm.makePersistence(x);

            count++;
            if(count>=1000){
            trans.commit();
            trans.begin();
            pm=new InitialContext().lookup(...)....;

            }
            }
            trans.commit();
            System.out.println("complete");

            But I think the code is very bad. Can't I persist a lot of object in a single transaction??

            • 3. Re: Out of memory exception ....
              Juha Lindfors Master

              > Can't I persist a lot of object in a single transaction??

              Yes you can if you have enough memory. What is your physical heap size you set for your JVM?

              Also, you're passing a reference to the object instance you created to the persistence manager. What guarantee is there that the PM is not holding on to that reference preventing it from being garbage collected (therefore eventually using up all your memory)? It is more than likely that it will hold on to your objects at least until you commit() the transaction (if the persistence occurs at commit time). Therefore, you need to have enough memory to hold all those objects in memory until there is a commit.

              Again, this has nothing specific to do with JBoss. It is more of a matter how memory management in Java works.

              -- Juha

              • 4. Re: Out of memory exception ....
                wayyoung Newbie

                Thax for your reply again. I think you are right. I think that I mis-understand the meaning of "soft-reference". I think that the PM will try to store the object automatically even current transaction has not yet commit. By the way, can you tell me what is the difference between the soft-refernce and the hard-reference??

                • 5. Re: Out of memory exception ....
                  Juha Lindfors Master

                  The JVM may garbage collect soft referenced objects if it needs to reclaim more memory. All soft referenced objects should be garbage collected before an OutOfMemoryException is thrown.

                  -- Juha