好的,以防万一,这里有一个关于该问题的相关链接,基本上说没有修复,因为它是 JSF 机制所固有的。我求助于对视图数量使用参数 step ,这似乎更干净。
但我也尝试了一些肮脏的修复。我把它贴在那里以供将来参考。使用风险自负,因为没有保证。
package com.mycompany.ajaxutils;
import javax.faces.application.StateManager;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import org.ajax4jsf.application.AjaxStateManager;
import org.ajax4jsf.util.LRUMap;
public class AjaxStateHelper {
private static final AjaxSateManagerUncover asmu = new AjaxSateManagerUncover(null);
public static void cleanAjaxStateManager() {
HttpSession currentSession = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
.getSession(false);
LRUMap lrumap = asmu.getLRUMap(currentSession.getAttribute(AjaxStateManager.class.getName()
+ ".VIEW_STATES_MAP"));
lrumap.clear();
}
/**
* This inner class is needed because we need to make a cast to a SynchronizedStateHolder
* which is an inner protected class inside AjaxStateManager
*/
protected static class AjaxSateManagerUncover extends AjaxStateManager {
public AjaxSateManagerUncover(StateManager parent) {
super(parent);
}
public LRUMap getLRUMap(Object stateMap) {
SynchronizedStateHolder s = (SynchronizedStateHolder) stateMap;
return s.getStateMap();
}
}
}
只需AjaxStateHelper.cleanAjaxStateManager();
从应用程序中需要它的任何位置调用,它就会为您释放内存。但要注意潜在的副作用,这是实验代码