PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Mar 29, 2024 5:44 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Memory usage grow up
PostPosted: Thu Jan 20, 2011 6:54 am 
Offline

Joined: Wed Jan 19, 2011 2:05 pm
Posts: 2
I have a big problem with ExceptionOutOfMemory. After save and close new document1.pdf with added pages from imported document2.pdf, memory usage should be around previous statement, but it's not. It is like the added pages are still in memory.

Code:
                     foreach (myFile in Directory.GetFiles(myPath))
                    {
                                 PdfDocument document = new PdfDocument();
                                 using (PdfDocument tmpImpDoc = PdfReader.Open(myFile, PdfDocumentOpenMode.Import))
                                {
                               
                                    foreach (PdfPage importPage in TmpImpDoc.Pages)
                                    {
                                        document.AddPage(importPage);
                                    }
                                }
                                document.Save(@"C:\new\" + Path.GetFileName(myFile));
                                document.Close();
                                document.Dispose();
                     }


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory usage grow up
PostPosted: Thu Jan 20, 2011 4:00 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
Perhaps you should be wrapping the "PdfDocument document = new PdfDocument();" statement in a using block as well, and perhaps set document = null, and tmpImpdoc = null before leaving the using scope to ensure that it gets collected.

In case you haven't, search the other posts on out of memory related things and you may find hints about this. I just know there have been many discussions on this topic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory usage grow up
PostPosted: Fri Jan 21, 2011 11:03 am 
Offline

Joined: Wed Jan 19, 2011 2:05 pm
Posts: 2
it doesn't work when document=null and tmpImpDoc = null. It works only if U import document but dont use add page from it. I think the problem is I cannot do tmpImpDoc.close() [throws an exception document cannot be modified].

PdfDocument document = new PdfDocument();" has to be in a using because that is only a shortcut of my code and i'm importing more docs in one.

Quote:
In case you haven't, search the other posts on out of memory related things and you may find hints about this. I just know there have been many discussions on this topic.

I was searchin and there's no answer on my problem.


Top
 Profile  
Reply with quote  
 Post subject: Re: Memory usage grow up
PostPosted: Fri Jan 21, 2011 3:10 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
While I haven't tried this specifically, this was what I meant. If the following still leaks memory, then it's worth a look.

If I'm wrong here, please correct me, I'd like to know that. :)

Code:
          foreach (myFile in Directory.GetFiles(myPath))
                    {
                           using (PdfDocument document = new PdfDocument())
                           {
                                 using (PdfDocument tmpImpDoc = PdfReader.Open(myFile, PdfDocumentOpenMode.Import))
                                {
                               
                                    foreach (PdfPage importPage in TmpImpDoc.Pages)
                                    {
                                        document.AddPage(importPage);
                                    }
                                }
                                document.Save(@"C:\new\" + Path.GetFileName(myFile));
                                document = null;   // explicitly Tell CLR " I'm not using this anymore "
                                tmpImpDoc = null; //     ...
                          }
                     }


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group