-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi~
我写了一个Server push页面,每10s去更新一下;具体操作是:
删除一个listbox及其items。
再new一个listbox及其items。同时给每一个listitems 加了一个onclick事件。
此页面跑个二天左右,就会报IE内存溢出的错误!汗~~。
不知到到底是什么原因造成的!
有没有人遇到过这个问题呢?
那又是什么原因造成的呢?!
急切!感谢!
請提供代碼及ZK版本
Hi~,
环境:ZK5.0,Tomcat5.5,JDK6.0+, IE6出现时间短,IE7相对出现时间长;
index.zul:
<?page title="Auto Generated index.zul"?> <zk> <zscript language="Java"> import com.test.TestServerPush; </zscript> <button label="Start" width="90px" onClick="TestServerPush.start(win_push)"/> <listbox id="win_push" width="100%" visible="true" fixedLayout="true" mold="paging" pageSize="99" multiple="true"> <listhead> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> <listheader label="o,god" width="25%"/> </listhead> </listbox> </zk>
package com.test; import org.zkoss.lang.Threads; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zul.Listbox; import org.zkoss.zul.Listcell; import org.zkoss.zul.Listitem; import org.zkoss.zk.ui.util.Clients; public class TestServerPush{ private static WorkingThread _thragentpush; public static void start(Listbox listbox) throws InterruptedException { final Desktop desktop = Executions.getCurrent().getDesktop(); if (desktop.isServerPushEnabled()) { ; } else { desktop.enableServerPush(true); _thragentpush = new WorkingThread(listbox); _thragentpush.start(); } } private static class WorkingThread extends Thread { private final Desktop _desktop; private final Listbox _listbox; public int M_Refresh = 2000; private WorkingThread(Listbox listbox) { _desktop = listbox.getDesktop(); _listbox = listbox; } public void run() { try { while (true) { if (_listbox.getDesktop() == null || !_desktop.isServerPushEnabled()) { _desktop.enableServerPush(false); return; } Executions.activate(_desktop); try { _listbox.getItems().clear(); for (int i = 0; i < 100; i++) { Listitem item = new Listitem(); /* item.addEventListener("onClick", new EventListener(){ public void onEvent(Event e)throws Exception { Clients.evalJavaScript("alert('o,shit!');"); } }); */ for(int j = 0; j < 12 ; j++){ Listcell cellTemp1 = new Listcell(); cellTemp1.setLabel("congkaishi"); cellTemp1.setParent(item); cellTemp1.addEventListener("onClick", new EventListener(){ public void onEvent(Event e)throws Exception{ Clients.evalJavaScript("alert('o,shit!');"); } }); } item.setParent(_listbox); } } finally { Executions.deactivate(_desktop); } Threads.sleep(M_Refresh); } } catch (InterruptedException ex) { } } } }
請問是使用5.0.3嗎?
所以你的範例要跑2天才會溢出?
您可以考慮升到5.0.3
我們有做一些內存的優化
Asked: 2010-07-28 22:45:30 +0800
Seen: 545 times
Last updated: Aug 05 '10