Page 1 of 1

Memory leak

Posted: Sat Jul 20, 2019 1:12 pm
by thrinaina
Hello,
During manual crop physical memory keep on increasing and application got hanged until manually end the it from task manager, thanks in advance.

Re: Memory leak

Posted: Tue Jul 23, 2019 5:06 pm
by Gabriela
Hello,

Could you please send us the code snippet you are using and the related document? Please provide us with all details so we can reproduce the issue on our end. Could you confirm you are using the latest published release: https://www.gdpicture.com/download-gdpicture/ ?
Thank you in advance.

Re: Memory leak

Posted: Thu Jul 25, 2019 7:29 am
by thrinaina
Hello,
Thank you for your response we are using gdpicture_10 and we too face the same issue in latest trial version (14.1.29)


******* This is the code for manual crop and related method after this we are saving that image and proceeding for the second one*****

public void Crop()
{
if (gdViewerCrop.IsRect())
{
gdViewerCrop.GetRectCoordinatesOnDocument(ref nLeft, ref nTop, ref nWidth, ref nHeight);
}
else
{
XtraMessageBox.Show(Translator.GetTranslatedText("Please select area to crop the image."), Translator.GetTranslatedText(Resources.Info), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SaveGraphicState();
imageChanged = true;
_SampleImageID = imageID;
Imaging.Crop(imageID, nLeft, nTop, nWidth, nHeight);
//Imaging.CropBorders(_SampleImageID, 98.0f, ReferencePoint.ReferencePointBottomRight, ref nLeft, ref nTop, ref nWidth, ref nHeight, ImagingContext.ContextUnknown);
lftbrdr = nLeft;
tpbrdr = nTop;
widthbrdr = nWidth;
heightbrdr = nHeight;
if (MediaId != 0 && Utils.GetConfigurationValue("RecordProcessingAction").ToLower() == "true")
{
query += " INSERT INTO LOG(MediaID,ImageName,Action,UserID,Parameters) VALUES(" + MediaId + ",N'" + Path.GetFileName(files[index]).Replace("'", "''") + "',N'Manual Crop'," + Resources.USERID + ",'" + nLeft + "," + nTop + "," + nWidth + "," + nHeight + "') ";
}

gdViewerCrop.DisplayFromGdPictureImage(_SampleImageID);
gvZoom.DisplayFromGdPictureImage(_SampleImageID);
gdViewerCrop.ClearRect();
GC.Collect();
GC.WaitForPendingFinalizers();
}
****************************************************************************************************************************************
private void SaveGraphicState()
{
try
{
int i = 0;
for (i = _undoIDX + 1; i <= UNDO_LEVELs - 1; i++)
{
if (_arlstImagesUndo != 0)
{
Imaging.ReleaseGdPictureImage(_arlstCloneImagesUndo);
_arlstImagesUndo = _arlstCloneImagesUndo = 0;
barBtnRedo.Enabled = false;
}
else
{
GC.Collect();
GC.WaitForPendingFinalizers();
break;
}
}
_undoIDX += 1;
_arlstImagesUndo[_undoIDX] = imageID;
_arlstCloneImagesUndo[_undoIDX] = Imaging.CreateClonedGdPictureImage(imageID);
imageID = _arlstCloneImagesUndo[_undoIDX];
if (_undoIDX >= 0)
{
this.barBtnUndo.Enabled = true;
}
//if it reached first image
else
{
this.barBtnUndo.Enabled = false;
}
}
catch (Exception ex)
{
Utils.insertLogErrors("Error: CropImages3, " + ex.Message, ex.StackTrace);
XtraMessageBox.Show(ex.Message, Translator.GetTranslatedText(Resources.Error), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}


****************************************************************************************************************************************
****************************************************************************************************************************************


****this is the code for save and next (for getting next image and continuing the process

****************************************************************************************************************************************
****************************************************************************************************************************************

public void Next()
{
SaveImage();
InsertActions();
Utils.ShowForm(this, StringConstants.FORM_PLEASE_WAIT, StringConstants.LOADING_IMAGE);
if (files.Length >1)
{
lciSaveBtn.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;

index++;
if (index < files.Length)
{

ReleaseImagefromObject();
string FileName = isPresentInSaveMedia();
if (!string.IsNullOrEmpty(FileName))
{
imageID = Imaging.CreateGdPictureImageFromFile(FileName);
orginalimageID = orginalImaging.CreateGdPictureImageFromFile(files[index]);

}
else
{
imageID = Imaging.CreateGdPictureImageFromFile(files[index]);
orginalimageID = orginalImaging.CreateGdPictureImageFromFile(files[index]);


}
gdViewerCrop.DisplayFromGdPictureImage(orginalimageID);
//*changes(22.02.17)
//added below line to display "Image M Of N"
lblImageMOfN.Text = "Image " + (index + 1) + " of " + files.Length;

gvOrginal.DisplayFromGdPictureImage(orginalimageID);
gvZoom.DisplayFromGdPictureImage(imageID);
if (!string.IsNullOrEmpty(Resources.targetfilepath))
{
imageID = orginalimageID;
}
tbninputs.SelectItem(index);
DrawRectangle();
object val = repositoryItemComboBox2.Items[index];
barEditItem1.EditValue = val;

}
else
{
Utils.CloseForm();
XtraMessageBox.Show(Translator.GetTranslatedText(StringConstants.AT_LAST_IMAGE), Translator.GetTranslatedText(Resources.Info), MessageBoxButtons.OK, MessageBoxIcon.Information);
Utils.ShowForm(this, StringConstants.FORM_PLEASE_WAIT, StringConstants.LOADING_IMAGE);
index--;
ReleaseImagefromObject();
string FileName = isPresentInSaveMedia();
if (!string.IsNullOrEmpty(FileName))
{
imageID = Imaging.CreateGdPictureImageFromFile(FileName);
orginalimageID = orginalImaging.CreateGdPictureImageFromFile(files[index]);

}
else
{
imageID = Imaging.CreateGdPictureImageFromFile(files[index]);
orginalimageID = orginalImaging.CreateGdPictureImageFromFile(files[index]);


}
//imageID = Imaging.CreateGdPictureImageFromFile(files[index]);
//orginalimageID = orginalImaging.CreateGdPictureImageFromFile(files[index]);

gdViewerCrop.DisplayFromGdPictureImage(orginalimageID);
//*changes(22.02.17)
//added below line to display "Image M Of N"
lblImageMOfN.Text = "Image " + (index + 1) + " of " + files.Length;

gvOrginal.DisplayFromGdPictureImage(orginalimageID);
gvZoom.DisplayFromGdPictureImage(imageID);
if (!string.IsNullOrEmpty(Resources.targetfilepath))
{
imageID = orginalimageID;
}
tbninputs.SelectItem(index);
DrawRectangle();
object val = repositoryItemComboBox2.Items[index];
barEditItem1.EditValue = val;
}
if (index >= files.Length - 1)
{
//*changes(27.12.16)
//added below line
lciSaveBtn.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;

btnPrevious.Enabled = true;
btnNext.Enabled = false;
barButtonItem17.Enabled = true;
barButtonItem18.Enabled = true;
barButtonItem22.Enabled = false;
barButtonItem21.Enabled = false;
}
else
{
//*changes(27.12.16)
//added below line
lciSaveBtn.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;

btnPrevious.Enabled = true;
btnNext.Enabled = true;
barButtonItem17.Enabled = true;
barButtonItem18.Enabled = true;
barButtonItem22.Enabled = true;
barButtonItem21.Enabled = true;
}
}
else if (files.Length==1)
{
//*changes(27.12.16)
//added below line
lciSaveBtn.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;

btnPrevious.Enabled = false;
btnNext.Enabled = false;
barButtonItem17.Enabled = false;
barButtonItem18.Enabled = false;
barButtonItem22.Enabled = false;
barButtonItem21.Enabled = false;
}
else
{
Utils.CloseForm();
XtraMessageBox.Show(Translator.GetTranslatedText(StringConstants.LOAD_IMAGES), Translator.GetTranslatedText(Resources.Warning), MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
refresh();
gdViewerCrop.ZoomMode = ViewerZoomMode.ZoomModeHeightViewer;
gvOrginal.ZoomMode = ViewerZoomMode.ZoomModeHeightViewer;
gvZoom.ZoomMode = ViewerZoomMode.ZoomModeHeightViewer;
Utils.CloseForm();
}
**************************************************************************************************************************************************
public void SaveImage()
{
if (string.IsNullOrEmpty(destinationfolder))
{
FolderBrowserDialog folder = new FolderBrowserDialog();
Utils.CloseForm();
DialogResult result = XtraMessageBox.Show(Translator.GetTranslatedText("Select Path where you want to save images."), Translator.GetTranslatedText(Resources.Info), MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (result == System.Windows.Forms.DialogResult.OK)
{
folder.ShowDialog();
destinationfolder = folder.SelectedPath;
}
else
{
return;
}
}

Utils.ShowForm(this, StringConstants.SAVE_ACTION, StringConstants.FORM_PLEASE_WAIT);
string extension = Path.GetExtension(files[index]);
string filename = Path.GetFileNameWithoutExtension(files[index]);
if (!File.Exists(destinationfolder + "\\" + filename + extension))
{
imageprocessor.SaveFile(imageID, destinationfolder + "\\" + filename + extension, Imaging.GetTiffCompression(imageID));

}
else
{
Utils.CloseForm();
if (imageChanged)
{
if (XtraMessageBox.Show(Translator.GetTranslatedText(filename + extension + " already exists.\nDo you want to replace it?"), Translator.GetTranslatedText("Confirm Save"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
Utils.ShowForm(this, StringConstants.SAVE_ACTION, StringConstants.FORM_PLEASE_WAIT);
//Old code
imageprocessor.SaveFile(imageID, destinationfolder + "\\" + filename + extension, Imaging.GetTiffCompression(imageID));
}
}
else
{
if (imageChanged)
if (XtraMessageBox.Show(Translator.GetTranslatedText(filename + extension + " already exists.\nDo you want to replace it?"), Translator.GetTranslatedText("Confirm Save"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
Utils.ShowForm(this, StringConstants.SAVE_ACTION, StringConstants.FORM_PLEASE_WAIT);
//Old code
imageprocessor.SaveFile(orginalimageID, destinationfolder + "\\" + filename + extension, Imaging.GetTiffCompression(orginalimageID));
}
}
}
SavedImages.Add(destinationfolder + "\\" + filename + extension);

gdViewerCrop.DisplayFromGdPictureImage(orginalimageID);
//*changes(22.02.17)
//added below line to display "Image M Of N"
lblImageMOfN.Text = "Image " + (index + 1) + " of " + files.Length;

gvZoom.DisplayFromGdPictureImage(imageID);

string fileName = tbninputs.GetItemFileSource(index).ToString();
tbninputs.SelectItem(index);
GC.Collect();
GC.WaitForPendingFinalizers();

}
****************************************************************************************************************************************
private void InsertActions()
{
if (!string.IsNullOrEmpty(query))
{
MetadataEntry metaentry = new MetadataEntry();
metaentry.MediaDataFieldsInsertData(query);
query = string.Empty;
}
}

****************************************************************************************************************************************
public void refresh()
{
try
{


for (int i = 0; i <= UNDO_LEVELs - 1; i++)
{
if (_arlstImagesUndo != 0)
{
Imaging.ReleaseGdPictureImage(_arlstImagesUndo);
Imaging.ReleaseGdPictureImage(_arlstCloneImagesUndo);
_arlstImagesUndo = 0;
barBtnRedo.Enabled = false;
}
else
{
break;
}
}
_arlstImagesUndo = new int[UNDO_LEVELs];
_arlstCloneImagesUndo = new int[UNDO_LEVELs];
_undoIDX = -1;

barBtnUndo.Enabled = false;
barBtnRedo.Enabled = false;
}
catch (Exception ex)
{
Utils.insertLogErrors("Error: CropImages7, " + ex.Message, ex.StackTrace);
XtraMessageBox.Show(ex.Message, Translator.GetTranslatedText(Resources.Error), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}


****************************************************************************************************************************************

private void ReleaseImagefromObject()
{
Imaging.ReleaseGdPictureImage(imageID);
orginalImaging.ReleaseGdPictureImage(orginalimageID);
gdViewerCrop.ReleaseGdPictureImage(imageID);
gvOrginal.ReleaseGdPictureImage(orginalimageID);
gvZoom.ReleaseGdPictureImage(imageID);
imageID = 0;
orginalimageID = 0;
DeskewAngle = 0;
imageChanged = false;
GC.Collect();
GC.WaitForPendingFinalizers();
}


****************************************************************************************************************************************
Thanks&Regards,
Annapoorna.k

Re: Memory leak

Posted: Thu Jul 25, 2019 12:54 pm
by Gabriela
Hi,

Unfortunately, from such a code snippet we cannot investigate. If the issue is not possible to reproduce using only a simple piece of code, could you please provide a simple standalone application, that we can run "as is", which reproduces the issue (and only the issue) with the latest 14.1.29 release? The document you are using will be very useful as well. You can also submit a ticket with all relevant materials through our helpdesk: https://orpalis.zendesk.com
Thank you.

Re: Memory leak

Posted: Mon Jul 29, 2019 8:15 am
by thrinaina
Hello,
Simple code for crop and saving images.
****************************************************************************************************************************************
------------for images loading-----------------
****************************************************************************************************************************************
private void btnLoadOTIFF_Click(object sender, EventArgs e)
{
string[] files;
public static string[] fileslist;
public static string sourcefilepath = "";
files = Directory.GetFiles(sourcefilepath);
fileslist = files;
imageID = Imaging.CreateGdPictureImageFromFile(files[index]);
orginalimageID = orginalImaging.CreateGdPictureImageFromFile(files[index]);
}
****************************************************************************************************************************************
--------getting coordinates for images to crop----------------------------------------------------------------------------
****************************************************************************************************************************************
private void button1_Click(object sender, EventArgs e)
{
if (gdViewerCrop.IsRect())
{
gdViewerCrop.GetRectCoordinatesOnDocument(ref nLeft, ref nTop, ref nWidth, ref nHeight);
}
else
{
XtraMessageBox.Show(Translator.GetTranslatedText("Please select area to crop the image."), Translator.GetTranslatedText(Resources.Info), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
imageChanged = true;
_SampleImageID = imageID;
Imaging.Crop(imageID, nLeft, nTop, nWidth, nHeight);
lftbrdr = nLeft;
tpbrdr = nTop;
widthbrdr = nWidth;
heightbrdr = nHeight;
GC.Collect();
GC.WaitForPendingFinalizers();
}
****************************************************************************************************************************************
--------for saving and getting next----------------------------------------------------------------------------
****************************************************************************************************************************************
private void btnNext_Click(object sender, EventArgs e)
{
string extension = Path.GetExtension(files[index]);
string filename = Path.GetFileNameWithoutExtension(files[index]);
TiffCompression tifcomp = Imaging.GetTiffCompression(m_CurrentImage);
if (!File.Exists(destinationfolder))
{
imageprocessor.SaveFile(imageID, destinationfolder + "\\" + filename + extension, Imaging.GetTiffCompression(imageID));
}
else
{
Utils.CloseForm();
if (imageChanged)
{
if (XtraMessageBox.Show(Translator.GetTranslatedText(filename + extension + " already exists.\nDo you want to replace it?"), Translator.GetTranslatedText("Confirm Save"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
Utils.ShowForm(this, StringConstants.SAVE_ACTION, StringConstants.FORM_PLEASE_WAIT);
imageprocessor.SaveFile(imageID, destinationfolder + "\\" + filename + extension, Imaging.GetTiffCompression(imageID));
}
}
else
{
if (imageChanged)
if (XtraMessageBox.Show(Translator.GetTranslatedText(filename + extension + " already exists.\nDo you want to replace it?"), Translator.GetTranslatedText("Confirm Save"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
Utils.ShowForm(this, StringConstants.SAVE_ACTION, StringConstants.FORM_PLEASE_WAIT);
imageprocessor.SaveFile(imageID, destinationfolder + "\\" + filename + extension, Imaging.GetTiffCompression(imageID));
}
}
}
SavedImages.Add(destinationfolder + "\\" + filename + extension);
}


Thanks&Regards,
annapoorna.k

Re: Memory leak

Posted: Mon Jul 29, 2019 12:33 pm
by Gabriela
Hello,

I'm sorry to say that, but we really cannot investigate such code.
We strongly suggest paying attention to releasing images after the usage, either with ReleaseGdPictureImage Method (GdPictureImaging) or you can use also ReleaseAllGdPictureImages Method (GdPictureDocumentUtilities).
Please crosscheck your application. Or as I have already mentioned, you can send us a very simple application that demonstrates the issue if it still persists. Thank you for understandings.