Hi there,
We experienced some performance issues due to full heap memory so i started to profile and take regular heap snapshots and tried tracking down the cause by diffing the results.
Problems start after some days with heavy usage, heap dumps show a _huge_ number of instances of the following classes:
com.icesoft.faces.component.outputresource.RegisteredResource
com.icesoft.faces.webapp.http.core.ResourceDispatcher$ResourceServer$1
com.icesoft.faces.webapp.http.core.ResourceDispatcher$ResourceServer
As a side info: We have a bunch of outputResources in our app which are always visible and change hashcode very frequently.
What i found out is the following: (line numbers refer to current line numbers on HEAD at sventon.icefaces.org)
MainSessionBoundServlet.java:
Code:
77: final ResourceDispatcher resourceDispatcher = new ResourceDispatcher(ResourcePrefix, mimeTypeMatcher, sessionMonitor, configuration);
ResourceDispatcher is created once in the mainsession servlet and passed down through some layers until it reaches...
BridgeFacesContext.java:
Code:
167: this.resourceDispatcher = resourceDispatcher;
... at the constructor and is referenced there. So if i got everything right we just have one Instance of the ResourceDispatcher and every FacesContext holds a reference to it.
OutputResource.java:
Code:
90: path = ((ResourceRegistry) FacesContext.getCurrentInstance()).registerResource(
91: r).getRawPath();
Every OutputResource component registers its resources there.
ResourceDispatcher.java:
Code:
87: registered.add(name);
88: dispatcher.dispatchOn(".*" + name.replaceAll("\\/", "\\/") + dispatchFilename + "$", new ResourceServer(resource));
Every ResourceName gets added to the "registered" ArrayList and the ArrayList only gets cleared in the shutdown() method. (Which is called on context shutdown if i got everything right). Memory Leak 1
PathDispatcherServer.java:
Code:
32: public void dispatchOn(String pathExpression, final Server toServer) {
33: matchers.add(Pattern.compile(pathExpression));
34: servers.add(toServer);
35: }
For every Resource a expression gets added to "matchers" ArrayList, like before the ArrayList ony gets cleared in the shutdown() method. Same applies to "servers" ArrayList. Where servers List is the greate evil because toServer contains a pointer to the resource itself, so the resources also stay in memory. Memory Leak 2
I think this was left undiscovered for a long time as only heavy usage of OuputResources leads to a problem after some uptime of the application server.
We also have a Developer Support Contract, would be nice if this could be fixed asap. Please notify me if we should open a support ticket in addition to that detailed description.
Imho some garbage collection for old resources is needed there and maybe a contextparam to configure resource maximum age.