Free Support Forum - aspose.com

Please help on, out of memory issue

Exception in thread “Thread-3” java.lang.OutOfMemoryError: Java heap space
at com.aspose.email.system.io.MemoryStream.setCapacity(Unknown Source)
at com.aspose.email.system.io.MemoryStream.b(Unknown Source)
at com.aspose.email.system.io.MemoryStream.write(Unknown Source)
at com.aspose.email.ajo.a(SourceFile:370)
at com.aspose.email.tf.a(SourceFile:282)
at com.aspose.email.tf.a(SourceFile:307)
at com.aspose.email.tf.a(SourceFile:242)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.a(SourceFile:232)
at com.aspose.email.tf.b(SourceFile:157)
at com.aspose.email.alk.a(SourceFile:133)
at com.aspose.email.kn.a(SourceFile:51)
at com.aspose.email.afg.a(SourceFile:69)
at com.aspose.email.bv.a(SourceFile:119)
at com.aspose.email.afg.a(SourceFile:69)
at com.aspose.email.MapiMessageReader.readMessage(SourceFile:137)
at com.aspose.email.MapiMessage.a(SourceFile:3286)
at com.aspose.email.MapiMessage.a(SourceFile:4267)
at com.aspose.email.MapiMessage.a(SourceFile:2253)
at com.aspose.email.MapiMessage.e(SourceFile:2155)
at com.aspose.email.MapiAttachment.a(SourceFile:616)
at com.aspose.email.MapiAttachment.a(SourceFile:520)
at com.aspose.email.ada.a(SourceFile:2047)
at com.aspose.email.ada.a(SourceFile:1393)

@nicq.chen,

Thank you for contacting Aspose Support. Please provide additional details on when the exception occurs. If possible, please share the sample code as well so that we can investigate this further.

MailMessage eml = MailMessage.load(new ByteArrayInputStream(attachment.getBinaryData()), new EmlLoadOptions());

                        MapiConversionOptions options = new MapiConversionOptions();
                        options.setPreserveOriginalAddresses(false);
                        MapiMessage msg = MapiMessage.fromMailMessage(eml, options);
                        targetFolder.addMessage(msg);
                        eml.dispose();
                        msg.dispose();

@nicq.chen,

We were unable to reproduce the issue that you reported. We used the code snippet given below for testing.

PersonalStorage pst = PersonalStorage.create("newSample.pst", 0);
pst.getRootFolder().addSubFolder("myInbox");

MapiMessage mapiMessage = MapiMessage.fromFile("test.msg");
MapiAttachment attachment = mapiMessage.getAttachments().get_Item(0);
        
MailMessage eml = MailMessage.load(new ByteArrayInputStream(attachment.getBinaryData()), new EmlLoadOptions());
System.out.println(eml.getSubject());
MapiConversionOptions options = new MapiConversionOptions();
options.setPreserveOriginalAddresses(false);
MapiMessage msg = MapiMessage.fromMailMessage(eml, options);
FolderInfo targetFolder = pst.getRootFolder().getSubFolder("myInbox");
targetFolder.addMessage(msg);
MessageInfoCollection messageInfoCollection = targetFolder.getContents();
System.out.println(messageInfoCollection.size());
eml.dispose();
msg.dispose();

Please make sure that you are using the latest version of Aspose.Email for Java API. If the issue persists, please share the sample file so that we can investigate this further.