I looked at the introduction to method dispose() in Aspose.Email for Java, but I’m not sure how I should use it to flush memory. The below is my code:
PersonalStorage personalStorage = PersonalStorage.create(currentPstFilePath, FileFormatVersion.Unicode);
FolderInfo inboxFolder = personalStorage.getRootFolder().addSubFolder("Inbox");
for (Path emlFile : fileSet) {
try {
MailMessage eml = MailMessage.load(emlFile.toString());
inboxFolder.addMessage(MapiMessage.fromMailMessage(eml));
eml.dispose();
} catch (Exception e) {
log.error("Error processing file: %s,%s".formatted(emlFile, e.getMessage()));
log.error(Arrays.toString(e.getStackTrace()));
}
}
personalStorage.close();
In the above for-loop, after it adds MailMessage eml to inboxFolder it call dispose() for this eml. Later, it throws NPE exception but it does not affect the EML to PST conversion. I still see the size of PST file increasing. Also, I don’t see any memory release on JVM heap. So I’m curious about the role of dispose and how to use it correctly for MailMessage and PersonalStorage.