Memory Problems with String

Ken <[email protected]> Thu, 7 Sep 2006 15:44:07 +0000 (UTC)
Newsgroups gmane.comp.mozilla.jrex
Message-ID <[email protected]>
Hello all,

I notice a large number of string objects are accumulated when JRex navigating 
to different pages.  My profiling information points to xpcomInitImpl$1.run() 
as the source of the allocations.

The uncollected strings seem to be http headers information.  They have values 
including, "Content-Length", "text/html", and etc. 

Has anyone encounters this similar problem?

Could it possible there are caching options I need to set in JRex?  Or 
something I am not using correctly in JRex?

I used one of the sample testers in the existing postings.  It is included at 
the end of this post.  After each page is loaded, the number of string objects 
will increase from xpcomInitImpl$1.run() without garbage collected, until the 
tester is terminated.

Thanks for taking your times reading my questions.  Please let me know if 
there is more information I can provide.

Thanks,
Ken

 

package test;

import org.mozilla.jrex.JRexFactory; 
import org.mozilla.jrex.event.window.WindowListener; 
import org.mozilla.jrex.navigation.WebNavigation; 
import org.mozilla.jrex.navigation.WebNavigationConstants; 
import org.mozilla.jrex.window.JRexWindowManager; 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;  
import javax.swing.JFrame; 
import javax.swing.JPanel; 

public class JRexTest implements WindowListener { 

     int _nativePeerId = -1; 

     public static void main(String args[]) throws Exception { 
         new JRexTest().runMe(); 
     } 

     public void runMe() throws Exception { 
         boolean enableDom = true; 
         boolean loadDocument = true; 
         JFrame f = new JFrame(); 
         JPanel p = new JPanel(); 
         f.getContentPane().add(p); 
         p.setPreferredSize(new java.awt.Dimension(500, 300)); 
         p.setSize(new java.awt.Dimension(500, 300)); 
         p.setMinimumSize(new java.awt.Dimension(500, 300)); 
         f.setVisible(true);
         
         // TODO: Insert your GRE path
         System.setProperty("jrex.gre.path", "C:\\jrex\\gre"); 
         System.setProperty("jrex.dom.enable", String.valueOf(enableDom)); 
         JRexFactory.getInstance().startEngine(); 

         JRexWindowManager winManager = (JRexWindowManager) 
             JRexFactory.getInstance().getImplInstance
(JRexFactory.WINDOW_MANAGER); 

         winManager.create(JRexWindowManager.TAB_MODE); 
         winManager.addJRexWindowListener(this); 
         winManager.init(p); 

         waitForNativePeerId(); 
         winManager.removeJRexWindowListener(); 

         org.mozilla.jrex.ui.JRexCanvas browser = 
             winManager.getBrowser(_nativePeerId); 

         WebNavigation navigation    = browser.getNavigator(); 
         ArrayList<String> startUris = new ArrayList<String>();

         // TODO: Insert your own URLs
         startUris.add("C:\\jrex\\testpages\\test1.htm"); 
         startUris.add("C:\\jrex\\testpages\\test2.htm"); 
         startUris.add("C:\\jrex\\testpages\\test3.htm"); 

         String referrer = null; 
         int i = 1; 
         boolean done = false;
         BufferedReader in = new BufferedReader(new InputStreamReader
(System.in));

         while (!done)
         {
             System.out.println("0. Exit");
             System.out.println("1. Load pages again");
             int option = 2;

             try {
                 option = Integer.parseInt(in.readLine());
             } catch (Exception e) {
             }

             switch (option)
             {
                 case 0:
                     done = true;
                     break;
                    
                 case 1:
                     for (int j = 1; j <= 10; j++) { 
                         for (String uri : startUris) { 
                             System.err.println(""); 
                             System.err.println("------------------------------
------------------------i=" + (i++)); 
                             System.err.println(""); 
                             navigation.loadURI(uri, 
                                 WebNavigationConstants.LOAD_FLAGS_NONE, 
referrer, null, null);                           

                             try { 
                                 System.err.println("sleeping"); 
                                 System.gc(); 
                                 Thread.sleep(1000); 
                                 System.err.println("awake"); 
                             } catch (Throwable e) { 
                                 e.printStackTrace(); 
                             } 
                         } 
                     }
                     break;

                 }          
         }

         System.err.println("--------------------------DONE--------------------
----"); 

     } 

     // 
     // WindowListener methods 
     // 
     public void windowCreated(int jrexPeerID) { 

         if (_nativePeerId == -1) { 
             synchronized (this) { 
                 _nativePeerId = jrexPeerID; 

                 this.notifyAll(); 
             } 
         } 
     } 

     public void windowDisposing(int jrexPeerID) { 
     } 

     // 
     // JRex state utility methods 
     // 

     public synchronized void waitForNativePeerId() { 
         synchronized (this) { 
             while (_nativePeerId == -1) { 
                 try { 
                     this.wait(); 
                 } catch (InterruptedException e) { 
                     e.printStackTrace(); 
                 } 
             } 
         } 
     }
}