Java heap space during load message in pst

Our client has some issue during download outlook message from our API, his failed message has size 18mb

java.lang.OutOfMemoryError: Java heap space
at java.base/java.lang.StringLatin1.toChars(StringLatin1.java:73)
at java.base/java.lang.String.toCharArray(String.java:2855)
at com.aspose.email.internal.b.zar.c(SourceFile:1975)
at com.aspose.email.internal.b.zar.g(SourceFile:1960)
at com.aspose.email.internal.ae.zl.c(Unknown Source)
at com.aspose.email.zatg.f(SourceFile:385)
at com.aspose.email.MapiMessage.a(SourceFile:4821)
at com.aspose.email.MapiMessage.h(SourceFile:4569)
at com.aspose.email.MapiMessage.a(SourceFile:3374)
at com.aspose.email.MapiMessage.b(SourceFile:2952)
at com.aspose.email.MapiMessage.fromMailMessage(SourceFile:1683)

try (StorageObjectInputStream storageObjectInputStream = storageService.get(StorageHelper.makeObjectKey(
			context.getAccount().getId(),
			context.getUser().getId(),
			ProcessUtils.buildServiceName(context.getTask().getProcessType()),
			messageItem.getContentId()));
		 MailMessage mailMessage = MailMessage.load(storageObjectInputStream)) {

		mailMessage.setSubject(Optional.ofNullable(mailMessage.getSubject()).orElse(messageItem.getSubject()));
		MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, MapiConversionOptions.getUnicodeFormat());
		folder.addMessage(mapiMessage);
		mailMessage.dispose();
		mapiMessage.dispose();
	}

@Dolhyi_Dmytro

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input PST file.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

failed.pst.zip (343.1 KB)

if operation is executed for single file, issue can not be reproduced, you need to execute current operation for a data list and have a large file size.

File file = new File("file_failed.pst");
	try (PersonalStorage storage = PersonalStorage.create(file.getAbsolutePath(), 0)) {
		FolderInfo folder = storage.getRootFolder().addSubFolder("Test folder");

		InputStream stream = new FileInputStream("failed.pst");

		MailMessage mailMessage = MailMessage.load(stream);
		mailMessage.setSubject("test subject");
		MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, MapiConversionOptions.getUnicodeFormat());
		folder.addMessage(mapiMessage);
		mailMessage.dispose();
		mapiMessage.dispose();
	}

@Dolhyi_Dmytro

We have tested the scenario using the latest version of Aspose.Email for Java 22.5 and have not found the shared issue. So, please use Aspose.Email for Java 22.5.

hi guys, i updated library version on production but current issue is not fixed. Client has 2k message items and some of them are large. Please research and fix

- ServiceProcess execution error! java.lang.OutOfMemoryError: Java heap space at java.base/java.lang.StringLatin1.toChars(StringLatin1.java:73) at java.base/java.lang.String.toCharArray(String.java:2855) at com.aspose.email.internal.b.zar.c(SourceFile:1975) at com.aspose.email.internal.b.zar.g(SourceFile:1960) at com.aspose.email.internal.ae.zl.c(Unknown Source) at com.aspose.email.zatg.f(SourceFile:385) at com.aspose.email.MapiMessage.a(SourceFile:4822) at com.aspose.email.MapiMessage.h(SourceFile:4570) at com.aspose.email.MapiMessage.a(SourceFile:3375) at com.aspose.email.MapiMessage.b(SourceFile:2953) at com.aspose.email.MapiMessage.fromMailMessage(SourceFile:1684) at

@Dolhyi_Dmytro

Could you please share complete detail of your working environment e.g. operating system, Java version, RAM of your system etc.?

Are you facing this issue with specific PST file that contains huge size email message?

openjdk version “11.0.15” 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode)

-Xmx768m

process for download working in one thread

@Dolhyi_Dmytro

Could you please share this detail?

I cant share you client message item details. If our company has already paid ID 210816095330, how can i obtain paid support or need pay by Paid Support service separately ?

@Dolhyi_Dmytro

We suggest you please check our paid support policies from following link.
Paid Support Policies