We have a memory issue while tagging 400 pdf documents. Is there any option to avoid this memory usage while tagging each PDF document?
Below is the code:
using (Aspose.Pdf.Document _pdfDocument = new Aspose.Pdf.Document(filepath))
{
if (File.Exists(filepath))
File.Delete(filepath);
Aspose.Pdf.Tagged.ITaggedContent taggedContent = _pdfDocument.TaggedContent;
// Set Title and Language for Documnet
taggedContent.SetTitle(Convert.ToString(doc.BuiltInDocumentProperties.Title));
taggedContent.SetLanguage(language);
using (MemoryStream _stream = new MemoryStream())
{
bool _IsConverted = _pdfDocument.Convert(_stream, Aspose.Pdf.PdfFormat.PDF_UA_1, Aspose.Pdf.ConvertErrorAction.None);
Aspose.Pdf.PdfSaveOptions options = new Aspose.Pdf.PdfSaveOptions();
_pdfDocument.Save(filepath, options);
var after = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
Logger.WriteLog(_log_filePath, "Memory Before GC collect :-" + after + ":- " + filepath);
_stream.Close();
_stream.Dispose();
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
@jithin.p
It is not very clear from the code provided how you determined the presence of leaks. Try this approach.
GC.Collect();
GC.WaitForPendingFinalizers();
var memoryBefore = GC.GetTotalMemory(true);
// your code
GC.Collect();
GC.WaitForPendingFinalizers();
var memoryAfter = GC.GetTotalMemory(true);
Console.WriteLine("delta is: " + memoryAfter - memoryBefore);
I will try this. The memory issue is occurring while processing 1000+ records at a time. Can you have any suggestions to reduce the memory usage while tagging and merging documents by checking the above code that I posted?
@jithin.p
So these are not memory leaks, but rather large (in your opinion) memory consumption?
@jithin.p
Then it is expected - each document needs to be opened, this requires memory, when there are many documents or they are large/complex - a lot of memory.
Hi,
Below are the codes from my application. Please guide me; do you have any suggestions to reduce the memory usage and thereby reduce the processing time?
//In **ss_List** we have 1000 records
// we are storing this to **finaldocInnerWord**
foreach (var _innerRow in ss_List)
{
Document temp = new Document(word_files_location + _innerRow.FileName);
temp.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
temp.FirstSection.HeadersFooters.LinkToPrevious(false);
finaldocInnerWord.AppendDocument(temp, ImportFormatMode.KeepSourceFormatting);
File.Delete(word_files_location + _innerRow.FileName);
temp = null;
}
finaldocInnerWord.FirstSection.Remove();
//Then we are appending **finaldocInnerWord** to **temp** and then saving the merged document to the folder. It is taking so much time.
if (File.Exists(_word_file_path))
{
Document temp = new Document(_word_file_path);
temp.AppendDocument(finaldocInnerWord, ImportFormatMode.KeepSourceFormatting);
temp.Save(_word_file_path);
temp = null;
}
@jithin.p Memory and CPU utilization fully depends on input document file size, format and complexity. Aspose.Words always allocates more memory that actual document size. This is expected. Please see our documentation for more information:
https://docs.aspose.com/words/net/memory-requirements/
For reducing memory usage upon processing extremally large documents, you can try using LoadOptions.TempFolder , SaveOptions.TempFolder and SaveOptions.MemoryOptimization properties.