Issue disposing of image
Posted: Wed Nov 09, 2016 12:27 pm
I am using the following code to loop through a number of PDF documents and doing OCR on them. The issue I am having is that the picture is not being disposed and the new picture loaded. It seems to just continually process the first PDF uploaded. In the code below the foreach loops through the PDF files, while the inner for loop goes through each page of the PDF. The issues is that the first PDF document gets re-processed as many times as I have items in the foreach list.
Am I not disposing of the image correctly?
Am I not disposing of the image correctly?
Code: Select all
var allBlobs = container.ListBlobs(null, true, BlobListingDetails.All).Cast<CloudBlockBlob>();
foreach (CloudBlockBlob item in allBlobs)
{
if (item.GetType() == typeof(CloudBlockBlob) & item.Name.EndsWith(".pdf"))
{
// Read the file (blob) into a MemoryStream for conversion into a GdPicture element
using (MemoryStream memStream = new MemoryStream())
{
item.DownloadToStream(memStream);
// Convert memoryStream of the PDF into GdPicture element
GdPicturePDF picture = new GdPicturePDF();
picture.LoadFromStream(memStream);
int numPages = picture.GetPageCount();
#region Loop through all the pages in a document
for (int i = 1; i <= numPages; i++)
{
// Loop through all pages and do OCR
// Clean up memory and release the GdPictureImage
image.Dispose();
image.ReleaseGdPictureImage(imageId);
}
#endregion
// Done reading all pages so close document
picture.CloseDocument();
picture.Dispose();
}
// Delete the PDF document from Blob storage
item.Delete();
}
}