violetbeach opened a new pull request, #159:
URL: https://github.com/apache/commons-email/pull/159

   ### Issue
   
   Hello,
   
   OOM occurred in the mail service developed using Apache-commons-email.
   
   I debugged and found that the mail lookup function was wasting memory!
   
   ### Problem
   
   Below is a test for reproducing the problem.
   
   ```java
   @Test
   void memoryTest() throws Exception {
       InputStream is = new SharedFileInputStream("/test/oom.eml");
       Session session = Session.getInstance(System.getProperties());
       MimeMessage mimeMessage = new MimeMessage(session, is);
       MimeMessageParser parser = new MimeMessageParser(mimeMessage).parse();
   }
   ```
   
   Below is the memory usage.
   
   
![img](https://github.com/apache/commons-email/assets/63458653/721ddcb7-b30b-4688-afc4-6f773c85b6a8)
   
   I expected to write attachments to the buffer of the output stream when 
absolutely necessary.
   
   However, it is becoming a problem by putting all bytes[] in memory.
   
   
![img_3](https://github.com/apache/commons-email/assets/63458653/67c7f208-fc4a-4954-823a-3a6904d21dd7)
   
   
![img_1](https://github.com/apache/commons-email/assets/63458653/8b144f5a-2b15-4c9a-a070-4d179e0b1d09)
   
   ### Sugest
   
   So i modified these processes to use AttachmentDataSource.
   
   Attachment DataSource uses InputStream from original DataSource to ensure 
memory is not wasted.
   
   As a result, i can get a big effect in memory usage.
   
   
![img_2](https://github.com/apache/commons-email/assets/63458653/9adb56e3-8a57-49ad-aec7-1324860b0f30)
   
   > I worked hard to fix it. Feel free to let me know if you have any advice 
or lack!
   
   If you need the tested eml file, I will send it to you by email.
   
   Thanks very much. 🙇
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to