understanding ClearGdPicture
understanding ClearGdPicture
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()
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()
Re: understanding ClearGdPicture
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 !
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 !
Re: understanding ClearGdPicture
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!
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!
Re: understanding ClearGdPicture
Hi,
Good practice are:
- use one GdPcitureImaging instance per thread
- Call ClearGdPciture when no asynchronous process using GdPciture are running.
Good practice are:
- use one GdPcitureImaging instance per thread
- Call ClearGdPciture when no asynchronous process using GdPciture are running.
Re: understanding ClearGdPicture
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();
Re: understanding ClearGdPicture
Yes, exactly !
Re: understanding ClearGdPicture
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
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
Re: understanding ClearGdPicture
OK dude, thank you for your patience.
We should release next version very soon...
Cheers,
Loïc
We should release next version very soon...
Cheers,
Loïc
Re: understanding ClearGdPicture
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.
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?
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.
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);
Re: understanding ClearGdPicture
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
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
Re: understanding ClearGdPicture
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!
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;
}
}
Re: understanding ClearGdPicture
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
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
Who is online
Users browsing this forum: No registered users and 1 guest