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();
}
}