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?