understanding ClearGdPicture

Discussions about image processing and document imaging.
Post Reply
dixus
Posts: 39
Joined: Wed Feb 10, 2010 9:23 am

understanding ClearGdPicture

Post by dixus » Mon Oct 18, 2010 6:05 pm

I have some issues with ClearGdPicture. Without i get 100 MB memory leaks after scanning and detecting barcodes on about 70 pages.

Documentation says "is not thread safe".

But i use GdPictureImaging as an instance member of each worker thread.

So should i call it for each instance or once for all instances?

Calling it for each instance produces weird errors and null reference exceptions.
Also it randomly raises null reference exceptions calling ClearGdPicture() on a valid gdlib instance.
( viewtopic.php?t=2774 = same ?)

Thanks for your help.

dix

EDIT: i just saw that 7.1 is out. i used 7.0.0.0 - i will update and see if issue still occurs

EDIT: still the same. Calling ClearGdPicture after scanning and manipulating some images causes an internal null reference exception in gdpicture

EDIT: call stack doesnt tell much

bei ᐂ.ᗖ.ᗬ()
bei ᐂ.➩.ᗬ()
bei GdPicture.GdPictureImaging.ClearGdPicture()

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

Re: understanding ClearGdPicture

Post by Loïc » Mon Oct 18, 2010 6:39 pm

Hi,

First we identified a bug in this function in 7.1. 7.2 will correct it.

This function is not thread safe because it "purge" all images & reserved memory areas used by GdPicture core. These memory areas can be recycled by GdPciture during the cycle of life of your application. In fact it is a kind of customized Garbage Collector.
So if you have make a call to this function asynchronously, you will ruin current process accessing to GdPicture bitmaps & probably crash your application.

Hope this helps !

dixus
Posts: 39
Joined: Wed Feb 10, 2010 9:23 am

Re: understanding ClearGdPicture

Post by dixus » Mon Oct 18, 2010 6:42 pm

oh well, that means if i synchronize my processes and call cleanup at a secure moment and not during an operation it should work?

am i right if it makes no difference when i use a static gdpicture instance for all threads instead of one instance per worker therad?

thanks!

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

Re: understanding ClearGdPicture

Post by Loïc » Mon Oct 18, 2010 6:44 pm

Hi,

Good practice are:

- use one GdPcitureImaging instance per thread
- Call ClearGdPciture when no asynchronous process using GdPciture are running.

dixus
Posts: 39
Joined: Wed Feb 10, 2010 9:23 am

Re: understanding ClearGdPicture

Post by dixus » Mon Oct 18, 2010 6:47 pm

so i do not to call clearGdPicture in a thread. i can do something like this somewhere in my app?

Code: Select all

GdPictureImaging _gdLib = new GdPictureImaging();
_gdLib.ClearGdPicture();

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

Re: understanding ClearGdPicture

Post by Loïc » Mon Oct 18, 2010 6:48 pm

Yes, exactly !

dixus
Posts: 39
Joined: Wed Feb 10, 2010 9:23 am

Re: understanding ClearGdPicture

Post by dixus » Mon Oct 18, 2010 6:52 pm

okay i did so :)

the issue is that i still get the NullReference Exception... I will wait for your update and explain our customer, that they should restart the app after doing large scans :wink:

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

Re: understanding ClearGdPicture

Post by Loïc » Tue Oct 19, 2010 8:14 am

OK dude, thank you for your patience.

We should release next version very soon...

Cheers,

Loïc

dixus
Posts: 39
Joined: Wed Feb 10, 2010 9:23 am

Re: understanding ClearGdPicture

Post by dixus » Wed Oct 20, 2010 8:40 am

still got a question. Shouldnt i be able to pass on ClearGdPicture, when I clean each used GDPicture Image after using it?

My tests resulted in this numbers:

70 Page scan (with barcode recognition, thumbnail generation) in gray scale 300DPI raises memory usage of the app by around 120 MByte.

That means after doing seven of such large scans the app uses 1 GByte memory more than before the scans.
::bug::
What i dont understand is, that i use ReleaseGdPictureImage for all created Images, but it has no effect on the memory issue. Only ClearGdPicture cleans the RAM ( but crashes at every call). So should it be possible to live without ClearGdPicture when cleaning up each used image manually?
GdLib.ReleaseGdPictureImage(tmpId);

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

Re: understanding ClearGdPicture

Post by Loïc » Wed Oct 20, 2010 9:22 am

Hi,

ReleaseGdPictureImage should work without any issue. Maybe you have a memory leak somewhere else.
If you me a code snippet reproducing the issue I will be happy to help !



Cheers,

Loïc

dixus
Posts: 39
Joined: Wed Feb 10, 2010 9:23 am

Re: understanding ClearGdPicture

Post by dixus » Wed Oct 20, 2010 11:06 am

the TWAIN code looks like this... It uses a method to split the files during the scan process. I cant find any image that i doesnt release. Probably you can see a code position that i should investigate closor.

TY!

Code: Select all


protected override void ExecuteService()
{
            int page = 0;
            int twainImgId;
            int documentImgId = 0;           

            do{         
                twainImgId = GdLib.TwainAcquireToGdPictureImage(IntPtr.Zero);
                if (twainImgId != 0)
                {
                    documentImgId = SplittTifByBarcode(path, page, documentImgId, twainImgId);
                    GdLib.ReleaseGdPictureImage(twainImgId);
                }

            } while ((twainImgId != 0) && (GdLib.TwainGetState() > TwainStatus.TWAIN_SOURCE_OPEN));


            if (documentImgId != 0)
            {
                GdLib.TiffCloseMultiPageFile(documentImgId);
                GdLib.ReleaseGdPictureImage(documentImgId);            
            }

            GdLib.TwainCloseSourceManager(IntPtr.Zero);
            GdLib.TwainCloseSource();
 }

 public int SplittTifByBarcode(string path, int page, int tiffId, int sourceId)
        {

            if (GdLib.Barcode1DReaderDoScan(sourceId, Barcode1DReaderScanMode.BestQuality) == GdPictureStatus.OK)
            {              
                int barcodeNo = GetBarcodeValue(out barcodeValue);
                //create new document if barcode on that page
                int tmpId;
                if (barcodeNo > 0)
                {                   
                    if (tiffId > 0)
                    {
                        GdLib.TiffCloseMultiPageFile(tiffId);
                        GdLib.ReleaseGdPictureImage(tiffId);
                        RaiseCreatedEvent();
                    }
                    tiffId = GdLib.CreateClonedGdPictureImage(sourceId);
                    ConvertImageToOutputType(tiffId);                    
                    GdLib.TiffSaveAsMultiPageFile(tiffId, docpath, (TiffCompression)Config.TiffCompressionMode);
                }
                else
                {
                    ConvertImageToOutputType(sourceId);
                    tiffId = CreateTifFile(tiffId, sourceId);
                }
            }
            return tiffId;
        }




        public void ConvertImageToOutputType(int destImageId)
        {
            switch (ImageType)
            {
                case ScanImageType.RGB:
                    break;
                case ScanImageType.GRAY:
                    GdLib.ConvertTo8BppGrayScale(destImageId);
                    break;
                default: ;
                    GdLib.ConvertTo1Bpp(destImageId);
                    break;
            }
        }

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

Re: understanding ClearGdPicture

Post by Loïc » Wed Oct 20, 2010 12:12 pm

Hi,

It is too hard to investigate the code without to be able to trace steps.

if you can write a tint standalone c# app reproducing the problem I will fix that. You can upload it through https://www.gdpicture.com/support/getting-support-from-our-team

Thank you for your comprehension.

Loïc

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest