Comments (5)
How do you know it is never cleared from memory? The garbage collection should remove it.
from pdfsharp.
Thread.Sleep(5000);
using (PdfDocument pdfDocument = PdfReader.Open("a.pdf", PdfDocumentOpenMode.Import))
{
pdfDocument.Dispose();
}
Console.WriteLine("pdfDocument should be closed and removed from memory");
Console.ReadKey();
In my understanding, when the program reaches Console.Writeline
, GC should remove pdfDocument from memory.
from pdfsharp.
GC runs when it runs - unless you invoke it explicitly.
At WriteLine the object should be disposed, but GC will not run automatically at every Dispose.
Application memory will not shrink even if heap has large unused areas.
What do you get when you do Import/Dispose 10 times in a loop?
Code to invoke GC:
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
from pdfsharp.
Thread.Sleep(5000);
for(int i = 0; i < 10; i++)
{
using (PdfDocument pdfDocument = PdfReader.Open("file.pdf", PdfDocumentOpenMode.Import))
{
pdfDocument.Dispose();
}
}
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
Console.WriteLine("pdfDocument should be closed and removed from memory");
Console.ReadKey();
Running GC manually does not seems to make any diffrence.
file.pdf is 489MB
from pdfsharp.
So it is about 500 MB after one cycle and about 500 MB after 10 cycles.
Looks as if garbage collection works as it should, even though it does not occur when you expect it.
from pdfsharp.
Related Issues (20)
- How to convert Byte[] to XImage in PdfSharp HOT 3
- DrawMatrixCode seems to be returns null always in .Net8 HOT 1
- Add initialization of XGraphicsPath from its native counterpart HOT 2
- How to build PDF Sharp with Strong name? HOT 3
- AddImage from Stream HOT 1
- Performance improvements HOT 2
- IndexOutOfRangeException when displaying a PNG HOT 3
- Exception when displaying some JPG with Core build HOT 3
- Colors from a PdfTextField are not stored HOT 2
- Rendering a document throws an `InvalidOperationException` if a paragraph gets close to the bottom of a page HOT 3
- IVS support HOT 1
- Invalid Surrogate Pair Check HOT 5
- Cannot open pdf file when SecuritySettings.OwnerPassword is set HOT 4
- MemoryStream's internal buffer cannot be accessed. HOT 1
- 6.1.0-preview-1 errors when opening file in framework 4.8 HOT 2
- The DrawImage Function Fails During Resizing HOT 1
- Allow table rows/cells to break across pages
- Initializing Migradoc DefaultPageSetup throws when CurrentCulture is a neutral culture HOT 2
- After pasting the image with a transparent background color into a PDF, it becomes a black background HOT 1
- Can't retrieve stream length error - in old version? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfsharp.