Free Support Forum - aspose.com

How to avoid OutOfMemoryExeption

Hi,

We are splitting very large pdf (thousands of pages, hundreds of mb in file size) and sometimes we got System.OutOfMemoryException. Full Exception stack (without our code calls) is

System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
at “a.›a.Write(Byte[] , Int32 , Int32 )
at ‡a.•...‡(•a , Š , Boolean , Int64& )
at ‡a.•...‡(•a , Š )
at .a.‡(•a , Š , Boolean , Int64& )
at .a.‡(•a , Š )
at ‡a....‡(•a , Š , Boolean , Int64& )
at ‡a....‡(•a , Š )
at .a.‡(•a , Š , Boolean , Int64& )
at .a.‡(•a , Š )
at ..a( , Int32 )
at ..a(•a , Boolean )
at ..Write(•a , Boolean )
at ..Save(•a , ‹a )
at ‚a.–.Save()
at ‚a.ŸŒ.Save(Stream )
at .›•.Save(Stream )
at Aspose.Pdf.Document.Save(Stream output)
at Aspose.Pdf.Document.Save(String outputFileName)

Is there any chance how I can optimize my code to avoid this?

We use Aspose.Pdf library for .NET 4. Library version is 10.6.0.0.

Kind Regards Jindrich

Hi Jindrich,


Thanks for your inquiry. Please note Aspose.Pdf API uses memory for processing, so performance depends upon the file size/contents and system resources. However, we will appreciate it if you please share your sample code and share some details about the size of file, in question. So we will try to replicate the issue at our end and will try to suggest you some workaround.

We are sorry for the inconvenience caused.

Best Regards,

As this is not small pdf file, where can I post it?

Hi Jindrich,


Thanks for your feedback. You may share it through some free file sharing service e.g dropbox, skydrive etc.

Moreover, please also confirm whether you are getting issue with some specific large PDF or all large PDF files.

Best Regards,

We run it with latest version now and it seems to be working…



We found another issue, I created another thread for it…



But OutOfMemory has been rising now in merge process (we combine x pdf files into one) resulting file is big as files described in this thread in split case. Stack trace looks different:



System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.

at ˆ€”.‡€”…ctor(Stream )

at ˆ€”.‡€”…ctor(Stream , Int32 , Int32 , Int32 , Int32 )

at œ□□.“□□.□„(Stream , Int32 , Object[] )

at œ□□.“□□.Š□(Stream , Stream , Int32 , Object[] )

at □□□.□□□.˜□□()

at □□.□□□.•□□(Š□□ , †□□ , Boolean )

at Aspose.Pdf.OperatorCollection.□□ƒ□()

at Aspose.Pdf.OperatorCollection.get_Count()

at —□□.˜□□.□□□□(OperatorCollection , Page )

at —□□.□□□□.□□□□()

at —□□.˜□□.□†□()

at —□□.□□□□.‹□‹□()

at —□□.˜□□.Process(XmlTextWriter , PdfFormat , Document , Boolean , ConvertErrorAction )

at Aspose.Pdf.Document.Convert(String outputLogFileName, PdfFormat format, ConvertErrorAction action)



Could this be issue of 32bit environment? Is Aspose.pdf compiled for 64bit?



Hi Jindrich,

jindrich.brezina:
We run it with latest version now and it seems to be working...


Thanks for your feedback. Should we disregard your email with sample code and document for splitting issue?

jindrich.brezina:

We found another issue, I created another thread for it... But OutOfMemory has been rising now in merge process (we combine x pdf files into one) resulting file is big as files described in this thread in split case. Stack trace looks different: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at ˆ€”.‡€”..ctor(Stream ) at ˆ€”.‡€”..ctor(Stream , Int32 , Int32 , Int32 , Int32 ) at œ□□.“□□.□„(Stream , Int32 , Object[] ) at œ□□.“□□.Š□(Stream , Stream , Int32 , Object[] ) at □□□.□□□.˜□□() at □□.□□□.•□□(Š□□ , †□□ , Boolean ) at Aspose.Pdf.OperatorCollection.□□ƒ□() at Aspose.Pdf.OperatorCollection.get_Count() at —□□.˜□□.□□□□(OperatorCollection , Page ) at —□□.□□□□.□□□□() at —□□.˜□□.□†□() at —□□.□□□□.‹□‹□() at —□□.˜□□.Process(XmlTextWriter , PdfFormat , Document , Boolean , ConvertErrorAction ) at Aspose.Pdf.Document.Convert(String outputLogFileName, PdfFormat format, ConvertErrorAction action) Could this be issue of 32bit environment? Is Aspose.pdf compiled for 64bit?


We will appreciate it if you please share your sample code and file. We will look into it and guide you accordingly. It is possible that the issue arises due to 32 bit environment because of memory. However we can confirm you after testing it at our end.

Moreover, please note same API can be used for both 32 and 64 bit environments.

Best Regards,

Using 64 bit was solution, now we can process really big files, thank you…So merging is ok.

Only issue left is one mentioned in other thread with filters, this processing is really slow. We do some internal investigation and it seems it is conversion issue into pdf/a and 1.4 pdf version, when we remove this convert commands all worked as expected.

So, one more time, OutOfMemory is solved, only issue left is slow pdf processing of pdf where mentioned filter is found

Hi Jindrich,


Thanks for your feedback. It is good to know that your above reported issues has been resolved.

Moreover, regarding the slow PDF processing issue, I am looking into it and will update you my findings in respective thread.

Best Regards,