2

I fetch messages from an IMAP folder using java mail api. We have a folder with 1000 messages. Suppose, the first message has UID 2000 and the last message has UID 8000.

When we perform get for all messages:

//call 1
// use indices, get the range 1-1000
Message m1[] = folder.getMessages(1, 1000);

consumes very few memory but on the other hand

//call 1
// use the first UID and last UID in the folder
Message m2[] = folder.getMessagesByUID(2000, 8000);

consumes a huge memory when analyzed with a profiler.

The returned arrays have same size and the members of the two arrays (the message templates) are totally same. But I can not explain why the call2 consumes huge memory?

benchpresser
  • 2,171
  • 2
  • 23
  • 41
  • 2
    Can you quantify the memory difference for us? – Max Feb 28 '17 at 15:22
  • If we looked in a profiler (yourkit for example, you see a difference of tens of mb. But it think i found the reason, when looking in the source of IMAPFolder, when calling getByUid, the messages are also put into a class scope hashtable (uidtable), if handling 10.000 messages, difference grows up. on the other side getMessages only picks up from messagecache. – benchpresser Feb 28 '17 at 21:30
  • I want to get all messages since last processed uid, for example f.getMessagedByUid(lastStored, UID.MAX), but if the folder contains 1million messages, and lastStored corresponds to a very old message, the call consumes too much memory. I think it is better to get the messagenumber of last processed message and call getMessages(msgnumberoflastprocessed, numallmessages) – benchpresser Feb 28 '17 at 21:35
  • suppose we want messages since uid 1000.option1: f.getMessagesByUID(1000, UIDMAX). option2: msgnum = f.getMessageByUID(1000).getMessageNumber(); f.getMessages(msgnum, allmessagecount) – benchpresser Feb 28 '17 at 21:38

0 Answers0