I'm creating a series of barcode catalogs, and am running into an Out of Memory exception when I run my program. I've tried removing the images from the catalog and the memory footprint is WAY smaller, but it still doesn't release any of the memory from the created PDFs until after they're all created. Here's the code I've come up with so far:
Code:
// individualCatalogs is a LiNQ expression pulling what I need from the database.
foreach (var catalog in individualCatalogs.ToList()) {
using (var pdf = new InventoryOperations().GenerateBarcodeCatalog(catalog)) {
using (FileStream s = File.Open(String.Format("MyCatalog{1}.pdf", catalog.Name), FileMode.Create)) {
pdf.Save(s);
pdf.Close();
pdf.Dispose();
s.Close();
s.Dispose();
}
}
GC.Collect();
}
As you can see, I've tried every trick I can think of to get the PDF to get collected after it's saved to disk. What have you guys tried? I need the barcodes in there too (XImage elements), and that's when things start crashing.