title: C# out of memory exception when converting a tiff file to pdf
body: <p>I have below code to convert multi-page TIFF to PDF. But I got out of memory issue and I do not know where.</p>
  <pre><code>public void convertTifToPDF(string destinaton, string sourceFile)
          {
              try
              {
                  PdfDocument doc = new PdfDocument();
  
                  Image myimage = Image.FromFile(sourceFile);
                  int numOfpages = myimage.GetFrameCount(FrameDimension.Page);
  
                  for (int index = 0; index &lt; numOfpages; index++)
                  {
                      myimage.SelectActiveFrame(FrameDimension.Page, index);
                      MemoryStream strm = new MemoryStream();
                      myimage.Save(strm, System.Drawing.Imaging.ImageFormat.Tiff);
                      XImage ximg = XImage.FromStream(strm);
                      var page = new PdfPage();
                      page.Height = ximg.PointHeight;
                      page.Width = ximg.PointWidth;
  
                      doc.Pages.Add(page);
                      XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[index]);
                      xgr.DrawImage(ximg, 0, 0);
                  }
                  doc.Save(destinaton + &quot;.pdf&quot;);
                  doc.Close();
                  myimage.Dispose();
              }
              catch (Exception ex)
              {
                  ErrorLog.LogError(ex, &quot;Error in: convertTifToPDF&quot;);
              }
          }
  </code></pre>
  <p>I know I need to dispose some objects but which one?</p>
  <p>Thanks for the help!!!</p>