Forums › TWAIN Classic › application memory and virtual memory increase quickly › Reply To: application memory and virtual memory increase quickly
Hi Gabe, thanks for your reply, yes, but i has use GlobalFree to release the handle, see my code segment. thanks again!
bool IMessageFilter.PreFilterMessage(ref Message m)
{
TwainCommand cmd = TwianScanner.PassMessage(ref m);
if (cmd == TwainCommand.Not)
return false;
switch (cmd)
{
case TwainCommand.CloseRequest:
{
EndingScan();
TwianScanner.CloseSrc();
break;
}
case TwainCommand.CloseOk:
{
EndingScan();
TwianScanner.CloseSrc();
break;
}
case TwainCommand.DeviceEvent:
{
break;
}
case TwainCommand.TransferReady:
{
ArrayList pics = TwianScanner.TransferPictures();
this.AutoScrollPosition = new Point(0, 0);
EndingScan();
TwianScanner.CloseSrc();
m_nPicnumber++;
for (int i = 0; i < pics.Count; i++)
{
IntPtr imgPtr = (IntPtr)pics;
IntPtr bmpptr = GlobalLock(imgPtr);
IntPtr pixptr = GetPixelInfo(bmpptr);
this.AutoScrollPosition = new Point(0, 0);
if (m_bmpOrigin!=null)
{
m_bmpOrigin.Dispose();
}
m_bmpOrigin = InptrToBitmap(pixptr, bmpptr);
Bitmap bmp = new Bitmap(m_bmpOrigin);
if (m_bFullSize)
{
pictureBox.Width = bmp.Width;
pictureBox.Height = bmp.Height;
}
else
{
pictureBox.Width = m_nPicOrgWidth;
pictureBox.Height = m_nPicOrgHeight;
bmp = new Bitmap(m_bmpOrigin, this.pictureBox.Width, this.pictureBox.Height);
}
m_nRotate = 1;
pictureBox.Image = bmp;
if (imgPtr != null)
{
GlobalFree(imgPtr);
}
if (bmpptr!=null)
{
GlobalFree(bmpptr);
}
if (pixptr!=null)
{
GlobalFree(pixptr);
}
}
if (pics!=null)
{
pics.Clear();
}
break;
}
}
return true;
}