Getting JAVA Heap Exception for traversing folders and mails from pst file

Hi,


I am trying to extract all mails from 1.82 GB pst file as follows,

FolderInfo folderInfo = this._personalStorage.getRootFolder();

traverse(folderInfo, folder);


void traverse(FolderInfo folderInfo) {

if (folderInfo.hasSubFolders() == true) {
IGenericEnumerable collection =
folderInfo.enumerateMapiMessages();

iterateCollectionToExtractData(); // This code takes nearly around 1 gb memory
for (int i = 0; i < folderInfo.getSubFolders().size(); i++) {
FolderInfo subfolderInfo = (FolderInfo) folderInfo
.getSubFolders().get_Item(i);
traverse(subfolderInfo );
}
}

Facing the
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.email.MapiProperty.b(SourceFile:807)
at com.aspose.email.ane.a(SourceFile:1811)
at com.aspose.email.ane.a(SourceFile:224)
at com.aspose.email.ane.b(SourceFile:1920)
at com.aspose.email.ane.a(SourceFile:2293)
at com.aspose.email.ane.a(SourceFile:279)
at com.aspose.email.ane$c.hasNext(SourceFile:3333)

Please let me know any other way to handle heap exception

Hi,


Thank you for contacting Aspose support team.

I have tested this issue using one sample PST of size 2.1 GB and extracted all the messages in the PST. I am afraid that no issue is observed and all the messages are extracted successfully. This issue seems to be specific to your PST file and needs further investigation. Could you please share your sample PST with us for our testing here? It will help us to observe the issue and provide assistance accordingly.