Out Of Memory Error

I’m trying to save a large PST file (17 gb) as separate MSGs. The bulk of the PST content is contained within a single sub-folder. When I try and begin iterating through the sub-folder with folderInfo.getContents(), the JVM is running out of memory (see below).

Is there any way to get the folder contents in a more incremental way so the process uses less memory at a given time? Also, do you have any information on the ratio of memory that a MessageInfoCollection object takes relative to the size of the folder it’s storing information on?

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–>

Exception in thread "AWT-EventQueue-2" java.lang.OutOfMemoryError: Java heap space

at java.lang.Object.clone(Native Method)

at sun.java2d.SunGraphics2D.clone(Unknown Source)

at sun.java2d.SunGraphics2D.create(Unknown Source)

at javax.swing.JComponent.paintComponent(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintToOffscreen(Unknown Source)

at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)

at javax.swing.RepaintManager.paint(Unknown Source)

at javax.swing.JComponent._paintImmediately(Unknown Source)

at javax.swing.JComponent.paintImmediately(Unknown Source)

at javax.swing.RepaintManager$3.run(Unknown Source)

at javax.swing.RepaintManager$3.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.access$1100(Unknown Source)

at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEventImpl(Unknown Source)

at java.awt.EventQueue.access$200(Unknown Source)

at java.awt.EventQueue$3.run(Unknown Source)

at java.awt.EventQueue$3.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–>

Hi Alex,


Thank you for writing to Aspose support.

Could you please try increasing the Java heap size and share your feedback with us after retrying the test? I would like to share that we had faced similar issues some times back but reading/writing to PST was improved a lot after that which solved this issue. I have further tested this scenario at my end using the latest version of Aspose.Email for Java 4.0.0 and a sample PST of size 19+ GB, which didn’t result in any such exception. Please note that I have set the Java heap size to -Xmx1000m. Though I am not able to face the exception with getContents() method, you may also try enumerating through the folder contents as shown in the following sample code.

Sample Code:

public void save2() {
String pstFileName = “sizelimit.pst”;
PersonalStorage pst = PersonalStorage.fromFile(pstFileName);
try {
FolderInfo inbox = pst.getRootFolder();
int i = 0;
for (String entryId : inbox.enumerateMessagesEntryId()) {
pst.saveMessageToFile(entryId, “message” + i++ + “.msg”);
}
} finally {
pst.dispose();
}
}