Re: Memory Problems with String
"Henry Chan" <henry_chan-VLMvL59Kb9lWk0Htik3J/[email protected]> Thu, 14 Sep 2006 19:50:16 -0400
| Newsgroups | gmane.comp.mozilla.jrex |
|---|---|
| Message-ID | <[email protected]> |
This issue is caused by the following files: JRex/src/native/JRexHeaderVisitorImpl.cpp JRex/src/native/JRexStreamListener.cpp JRex/src/native/JRex_JNI_ProgressEvent.cpp Originally, Find NewStringUTF in those files For example, the code in JRexHeaderVisitorImpl like env->CallObjectMethod(mHashTableObj,JRexHeaderVisitor::hashTablePutMID, env->NewStringUTF(headerChar),env->NewStringUTF(valueChar)); Change it to jstring key = env->NewStringUTF(headerChar); jstring value = env->NewStringUTF(valueChar); env->CallObjectMethod(mHashTableObj,JRexHeaderVisitor::hashTablePutMID,key,value); env->DeleteLocalRef(key); env->DeleteLocalRef(value); The string needs to be deleted the local reference, so the JVM can remove reference properly. "Ken" <[email protected]> wrote in message news:loom.20060907T173927-344-eS7Uydv5nfiQYT8SWwsb6uG/[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(); > } > } > } > } > }