Memory leak ?

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
kamichi
Posts: 8
Joined: Tue Apr 27, 2010 8:37 am

Memory leak ?

Post by kamichi » Tue Apr 27, 2010 9:01 am

Hello, there is my problem.

I scan many(>50) big images 300dpi, 25bit.
There is my .net code.

Code: Select all

        public bool s[b]omefunction()[/b]
        {
            GdPictureImaging oGdPictureImaging = new GdPictureImaging();
            oGdPictureImaging.SetLicenseNumber("XXXX");
            bool Res = true;
            oGdPictureImaging.TwainSetHideUI(false);
            try
            {
                int ImageID = 0;
                int NewTiffID = 0;
                int Counter = 0;
                bool NeChetPageBlank = false;
                bool ChetPageBlank = false;
                if (oGdPictureImaging.TwainOpenDefaultSource(this.Handle))
                {
                    do
                    {
                        ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(this.Handle);
                        if (ImageID != 0)
                        {
                            Counter++;
                            if ((Counter == 1))
                            {
                                NewTiffID = oGdPictureImaging.TiffCreateMultiPageFromGdPictureImage(ImageID);
                                oGdPictureImaging.ReleaseGdPictureImage(ImageID);
                            }
                            else
                            {
                                oGdPictureImaging.TiffAppendPageFromGdPictureImage(NewTiffID, ImageID);
                                oGdPictureImaging.ReleaseGdPictureImage(ImageID);
                            }

                           
                        }
                    } while (System.Convert.ToInt16(oGdPictureImaging.TwainGetState()) >
                             System.Convert.ToInt16(TwainStatus.TWAIN_SOURCE_ENABLED));
                    if (NewTiffID != 0)
                    {
                        string NewFileName = Path.Combine(Application.StartupPath,"Test.tiff");
                        
                        oGdPictureImaging.ReleaseGdPictureImage(NewTiffID);
                        NewTiffID = 0;

                    }
                    oGdPictureImaging.TwainCloseSource();
                    oGdPictureImaging.TwainUnloadSourceManager(this.Handle);
                    oGdPictureImaging.TwainCloseSourceManager(this.Handle);

                }

            }
            catch (Exception e)
            {

            }
            return Res;
        }
So, i scan 50 pages. Memory in task manager (about 700 mb). I finished scan. and wait. After 60 seconds memory (about 200 mb). My application after startup occupies abaut 10 MB. 200- 10 = 190. Why this memory dont free. Where is problem. Its test application whit one function somefunction() , and dont save any images just scan and test the memory.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Memory LEAK!!!

Post by Loïc » Tue Apr 27, 2010 11:44 am

Hi,

I tried your code without any memory leak.

Are you using the latest edition of the toolkit ?

After 60 seconds memory (about 200 mb). My application after startup occupies abaut 10 MB. 200- 10 = 190
This can be a normal behaviour of the .NET framework. A simple call to GC.Collect can recover all unused memory.

Kind regards,

Loïc

kamichi
Posts: 8
Joined: Tue Apr 27, 2010 8:37 am

Re: Memory leak ?

Post by kamichi » Tue Apr 27, 2010 3:29 pm

Thanks, Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest