B2022-025: Barakah print/merge of alarm gets out of memory error – dispose procs loaded in when resolving transition text

Added a null check
Added some aids for debugging the contentinfo cache
This commit is contained in:
Kathy Ruffing 2022-02-14 13:41:19 +00:00
parent bb81c62e3e
commit d4b7ea08a0
3 changed files with 65 additions and 4 deletions

View File

@ -3824,7 +3824,7 @@ namespace VEPROMS.CSLA.Library
try
{
ReadData(dr);
AddContent(dr);
//AddContent(dr); // B2022-025: memory leak. Content gets added in other places - this was adding it twice.
}
catch (Exception ex)
{
@ -6936,6 +6936,38 @@ namespace VEPROMS.CSLA.Library
}
return false;
}
// B2022-025: memory crash. Dispose was added to the TransitionLookup class to dispose of contents and items loaded in when
// resolving transition link text for procedures other than the current one being printed. The transition lookup code
// creates objects for a procedure if a transition points (external trans) to it and never disposes of these objects. For
// Barakah merged prints with alot of procedures to merge and when the procedures have external transitions, the program
// would crash with out of memory. Do not dispose of objects for the current procedure (int procID parameter) - this caused
// a crash.
public void Dispose(int procID)
{
foreach (Dictionary<int, ItemInfo> mylookup in MyLookups.Values)
{
if (mylookup != null)
{
foreach (ItemInfo ii in mylookup.Values)
{
if (ii.MyProcedure.ItemID != procID)
{
if (ii.MyContent.ContentParts != null)
{
foreach (PartInfo pi in ii.MyContent.ContentParts) pi.Dispose();
ii.MyContent.ContentParts.Dispose();
}
if (ii.MyContent.MyGrid != null) ii.MyContent.MyGrid.Dispose();
ii.MyContent.Dispose();
ii.Dispose();
}
}
mylookup.Clear();
}
}
MyLookups.Clear();
MyLookups = null;
}
}
#endregion
#region ProcedureInfo
@ -7149,6 +7181,10 @@ namespace VEPROMS.CSLA.Library
tmp.FromType = E_FromType.Procedure;
SetFromType(tmp);
SetParentSectionAndDocVersion(tmp, tmp.MyDocVersion, null, tmp.MyDocVersion, tranLookup);
// B2022-025: dispose cached items after setting transition text that gets done in SetParentSectionAndDocVersion & collect related garbage
tranLookup.Dispose(tmp.ItemID);
tranLookup = null;
GC.Collect();
//TimeSpan ts = DateTime.Now.Subtract(dt);
//ticksItems = ts.Ticks - (ticksROUsage + ticksTrans);
//ItemInfo.ShowTicks();

View File

@ -182,7 +182,7 @@ namespace VEPROMS.CSLA.Library
{
string key = "";
if (ovrrideChild == "")
if (ovrrideChild == null || ovrrideChild == "")
key = string.Format("{0}.{1}.{2}", ROFstID, dvi.DocVersionConfig.MaxSlaveIndex, dvi.DocVersionConfig.SelectedSlave);
else
key = string.Format("{0}.{1}.{2}", ROFstID, dvi.DocVersionConfig.MaxSlaveIndex, ovrrideChild); // C2021-065 use OTHER child information
@ -191,7 +191,7 @@ namespace VEPROMS.CSLA.Library
dicLookups.Clear(); //B2022-001 clear the dictionary each time to free up memory - out of memory fix
dicLookups.Add(key, new ROFSTLookup(this, dvi));
}
if (ovrrideChild != "")
if (ovrrideChild != null && ovrrideChild != "")
dicLookups[key].OtherChild = ovrrideChild; // C2021-065 use the OTHER applicabiltiy info to get RO Values
return dicLookups[key];
}

View File

@ -555,7 +555,15 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
private static int _ContentInfoUnique = 0;
private static int ContentInfoUnique
{ get { return ++_ContentInfoUnique; } }
{
get
{
int ui = ++_ContentInfoUnique;
// to debug to see where this gets allocated use the following code:
//if (ui == 2|| ui == 6) Console.WriteLine("Here");
return ui;
}
}
private int _MyContentInfoUnique = ContentInfoUnique;
public int MyContentInfoUnique // Absolutely Unique ID - Info
{ get { return _MyContentInfoUnique; } }
@ -580,6 +588,23 @@ namespace VEPROMS.CSLA.Library
{
_CountFinalized++;
}
// Use PrintCache in the CacheUsage.cs/CSLACache.Usage call to see what is in the cache for Contents.
// for printing the contentinfo objects in the cache, add the line 'ContentInfo.PrintCache();' to that method.
// NOTE that similar code can be added for the various csla wrapper objects, such as grid & item.
public static void PrintCache()
{
foreach (string str in _CacheByPrimaryKey.Keys)
{
List<ContentInfo> listContentInfo = _CacheByPrimaryKey[str]; // Get the list of items
if (listContentInfo.Count >1) Console.WriteLine("**Cache - {0}, count = {1}", str, listContentInfo.Count);
if (listContentInfo.Count > 1)
{
Console.WriteLine("**Cache - {0}, count = {1}", str, listContentInfo.Count);
foreach (ContentInfo ci in listContentInfo) Console.WriteLine(" num = {0}, uniqid = {1}, txt = {2}", ci.Number.Replace(@"\u8209?", "-"), ci.MyContentInfoUnique, ci.Text);
}
}
}
public void Dispose()
{
if (_Disposed) return;