views:

173

answers:

2

I'm running a server that uses Javamail. It has a count listener with IMAP's IDLE, such that when a new mail comes in, certain piece of code is executed. The list of new message is given to my listener as a parameter. I read the information off it and be done with it. All is good except my server leaks a lot of memory!! I did a heap dump and found that the class [Lcom.sun.mail.imap.IMAPMessage is using a lot of memory. It seems an array of IMAPMessage is referenced by the object com.sun.mail.imap.MessageCache.

Is there some caching going on? I don't need to access those messages ever again except for the first time it comes in. How do I force the cache to clear? How can I stop javamail from leaking?

A: 

You could try another Java Mail implementation if you don't like Sun's. GNU Classpath have one (at http://www.gnu.org/software/classpathx/javamail/javamail.html)

Moose Morals
+1  A: 

According to the docs, you pas a boolean to indicate that deleted messages should be expunged:

message.setFlag(Flags.Flag.DELETED, true);
folder.close(aBoolean);
store.close();
Miguel Ping