GarbageCollectObjects
Document properties, Optimisation
Description
Performs a mark-sweep garbage collection sweep immediately on the currently selected document to remove any orphaned indirect objects (objects that are no longer reachable from the catalog reference tree)
Syntax
Delphi
Function TPDFlib.GarbageCollectObjects: Integer;ActiveX
Function PDFlib::GarbageCollectObjects() As LongDLL
int DLGarbageCollectObjects(int InstanceID);Return values
| Negative value | Error during garbage collection |
|---|---|
| >= 0 | The number of orphaned indirect PDF objects that were removed from the document |
Remarks
This is useful after intensive document editing, page extraction, or object deletion, to shrink the document size before saving; you can also configure automatic garbage collection during saving using SetGarbageCollect
Example
PDF.LoadFromFile('edit.pdf', '');
PDF.DeletePages(5, 10); // delete some pages
PDF.GarbageCollectObjects; // free unreferenced objects immediately
PDF.SaveToFile('edit_cleaned.pdf');