GarbageCollectObjects
Document properties, Optimisation
Description
Performs a mark-sweep garbage collection immediately on the currently selected document to remove indirect objects that are no longer reachable from the complete trailer root graph, including private trailer extension keys.
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
Reachable objects are decoded on demand, and a decode failure aborts the sweep without deleting a partially traversed graph. Full saves rebuild object-stream membership after collection. 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');