[xwiki-dev] Possible memory leak ?

Vincent Massol vincent at massol.net
Tue Apr 10 10:54:50 CEST 2007


On Apr 10, 2007, at 10:15 AM, Pablo Oliveira wrote:

> On Apr 09, Ludovic Dubost wrote :
>> Right.. the XWikiContext with the classCache and archiveCache  
>> (which are
>> needed) is not made for being use for too long without cleaning up..
>> Maybe there should be some automated cleaning up when it gets too  
>> big..
>
> A simple non invasive solution, would be to use a LRUMap instead
> of a simple HashMap.
> It can be set to a maximum size and will use a Least Recently Used  
> elimination
> when full and adding a new object. See patch below.

Looks very good to me Pablo.

Some other things to take into account:

1) I see there's this method in XWikiContext:

     public BaseClass getBaseClass(String name) {
         return (BaseClass) classCache.get(name);
     }

This is too dangerous. I've checked and it's only used internally by  
XWikiContext.getClass(). It's dangerous because if we have a LRU  
strategy it could return null if some piece of code uses it. I  
believe this method should be removed altogether and the get from the  
map should be done directly in the getClass() method.

2) In XWikiHibernateVersioningStore, there's:

                 // This will also make sure that the Archive has a  
strong reference
                 // and will not be discarded as long as the context  
exists.
                 context.addDocumentArchive(key, archivedoc);

This will no longer be true. I'm not sure who wrote this comment and  
why it's good that a strong reference is kept during the whole  
lifecycle of the context... Whoever did this please come forward to  
explain! :)

3) Arnaud, do you think you could try what you've done with Pablo's  
patch and tell how it went? We need some verifications that it works  
fine before applying it.

4) Last, it would be great if someone could create a jira issue and  
attach pablo's patch

Thanks
-Vincent

> Index: core/src/main/java/com/xpn/xwiki/XWikiContext.java
> ===================================================================
> --- core/src/main/java/com/xpn/xwiki/XWikiContext.java  (revision  
> 2320)
> +++ core/src/main/java/com/xpn/xwiki/XWikiContext.java  (working copy)
> @@ -31,6 +31,7 @@
>  import com.xpn.xwiki.web.*;
>  import com.xpn.xwiki.validation.XWikiValidationStatus;
>  import org.apache.xmlrpc.server.XmlRpcServer;
> +import org.apache.commons.collections.map.LRUMap;
>
>  import java.net.URL;
>  import java.util.*;
> @@ -65,11 +66,13 @@
>     private String wikiOwner;
>     private XWikiDocument wikiServer;
>     private int cacheDuration = 0;
> +   private int classCacheSize = 10;
> +   private int archiveCacheSize = 10;
>
>     // Used to avoid recursive loading of documents if there are  
> recursives usage of classes
> -   private Map classCache = new HashMap();
> +   private Map classCache = new LRUMap(classCacheSize);
>     // Used to avoir reloading archives in the same request
> -   private Map archiveCache = new HashMap();
> +   private Map archiveCache = new LRUMap(archiveCacheSize);
>
> --
> Pablo
>
>
> --
> You receive this message as a subscriber of the xwiki- 
> dev at objectweb.org mailing list.
> To unsubscribe: mailto:xwiki-dev-unsubscribe at objectweb.org
> For general help: mailto:sympa at objectweb.org?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
> wws





More information about the devs mailing list