Post by BarryI have an application for which I have just written a new (memory
intensive) unit.
In the "Main" of the app, I have a series of "delete" and "new" calls to
all the units (non form type units).
When watching my RAM usage in Windows Task Manager, the app when
starting up, has used about 24Megs coming up to the following line
if (LongStrengths)
delete LongStrengths;
LongStrengths = new TLongStrengths;
and following the "new" above shoots up to 170Megs (which I can live
with, due to all the large 3 dimensional struct arrays that are defined
in that class, but surely when I call (delete LongStrengths) I should
get back down to 24Megs, whereas I only get down to say 143Megs, and on
calling the (new LongStrenths) again, my memory usage shoots up to say
260Megs....and so on and so forth.
Surely "delete LongStrengths" calls the Destructor of LongStrengths(),
and all my delete structs located in the destructor should free up all
that memory allocation?
Regards
Barry
If I step through the destructor of LongStrengths, it is called, but
when watching the memory usage in Windows Task Manager, I don't see it
change even by 1 Meg, as I step through all the delete's of the struct
arrays.....why am I not freeing up memories.
Constructor and Destructor of LongStrengths as follows:
//---------------------------------------------------------------------------
TLongStrengths::TLongStrengths() //Constructor
{
for (int k=0; k<MAXLIGHTDISTRITEMS; ++k)
{
LightDistr[k] = new LightDistrRecord;
LSPointLoads[k] = new LSPointLoadsRecord;
CalcDistr[k] = new CalcDistrRecord;
BuoyancyDistr[k] = new BuoyancyDistrRecord;
TanksCombinedWeightDistr[k] = new
TanksCombinedWeightDistrRecord;
LS1[k] = new LS1Record;
LightDistr[k]->Mass1 = 0;
LightDistr[k]->Mass2 = 0;
LightDistr[k]->Location1 = 0;
LightDistr[k]->Location2 = 0;
LightDistr[k]->Tcg = 0;
LightDistr[k]->Vcg = 0;
LSPointLoads[k]->Mass = 0;
LSPointLoads[k]->Lcg = 0;
LSPointLoads[k]->Tcg = 0;
LSPointLoads[k]->Vcg = 0;
CalcDistr[k]->Loc = 0;
CalcDistr[k]->LightMass = 0;
CalcDistr[k]->TotalMass = 0;
BuoyancyDistr[k]->Loc = 0;
BuoyancyDistr[k]->Mass = 0;
TanksCombinedWeightDistr[k]->Loc = 0;
TanksCombinedWeightDistr[k]->Mass = 0;
LS1[k]->Loc = 0;
LS1[k]->SF = 0;
LS1[k]->BM = 0;
}
for (int k=0; k<MAXFIXEDLOADS; ++k)
{
FixedLoadPointLoads[k] = new FixedLoadPointLoadsRecord;
FixedLoadPointLoads[k]->Mass = 0;
FixedLoadPointLoads[k]->Lcg = 0;
FixedLoadPointLoads[k]->Tcg = 0;
FixedLoadPointLoads[k]->Vcg = 0;
}
for (int k=0; k<MAXSHAPES; ++k)
{
ShapeHeader[k] = new ShapeHeaderRecord;
ShapeHeader[k]->ShapeName = "";
ShapeHeader[k]->EndOfTank = "";
ShapeHeader[k]->NoOfSections = 0;
ShapeHeader[k]->Bottom = 1000;
ShapeHeader[k]->Volume = 0;
ComponentHeader[k] = new ComponentHeaderRecord;
ComponentHeader[k]->ComponentName = "";
ComponentHeader[k]->ShapeName = "";
ComponentHeader[k]->LShift = 0;
ComponentHeader[k]->TShift = 0;
ComponentHeader[k]->VShift = 0;
ComponentHeader[k]->Side = 0;
ComponentHeader[k]->Effectiveness = 0;
PartHeader[k] = new PartHeaderRecord;
PartHeader[k]->PartName = "";
PartHeader[k]->PartDescr = "";
PartHeader[k]->Contents = "";
PartHeader[k]->LRef = 0;
PartHeader[k]->TRef = 0;
PartHeader[k]->VRef = 0;
PartHeader[k]->Type = 0;
PartHeader[k]->Density = 0;
PartHeader[k]->NoOfComponents = 0;
PartHeader[k]->Bottom = 1000;
PartHeader[k]->Sounding = 0;
PartHeader[k]->Volume = 0;
PartHeader[k]->Mass = 0;
for (int j=0; j<MAXCOMPONENTSPERPART; ++j)
{
PartData[k][j] = new PartDataRecord;
PartData[k][j]->CompName = "";
PartData[k][j]->CompNumber = 0;
PartData[k][j]->ShapeName = "";
PartData[k][j]->ShapeNumber = 0;
PartData[k][j]->Side = 0;
PartData[k][j]->Effectiveness = 0;
PartData[k][j]->SoundingFromBaseline = 0;
}
for (int j=0; j<MAXSECTIONS; ++j)
{
ShapeSectionHeader[k][j] = new ShapeSectionHeaderRecord;
ShapeSectionHeader[k][j]->Position = 0;
ShapeSectionHeader[k][j]->DepthAtPosition = 0;
ShapeSectionHeader[k][j]->MetricPosition = 0;
ShapeSectionHeader[k][j]->NoOfPoints = 0;
ShapeSectionHeader[k][j]->OffsetAtDepth = 0;
ShapeSectionHeader[k][j]->SectionHasArea = true;
ShapeSectionHeader[k][j]->Area = 0;
ShapeSectionHeader[k][j]->Top = 0;
ShapeSectionHeader[k][j]->PositionAtTop = 0;
ShapeSectionHeader[k][j]->Bottom = 1000;
ShapeSectionHeader[k][j]->LowestInboardOffset = 1000;
ShapeSectionHeader[k][j]->PositionOfLowestInboardOffset = 0;
for (int i=0; i<MAXOFFSETS; ++i)
{
ShapeSectionData[k][j][i] = new ShapeSectionDataRecord;
ShapeSectionReverseData[i] = new
ShapeSectionReverseDataRecord;
ShapeSectionData[k][j][i]->MetricOffset = 0;
ShapeSectionData[k][j][i]->MetricHeight = 0;
ShapeSectionReverseData[i]->MetricOffset = 0;
ShapeSectionReverseData[i]->MetricHeight = 0;
}
}
}
for (int i=0; i<MAXOFFSETS; ++i)
{
ShapeSectionReverseData[i] = new ShapeSectionReverseDataRecord;
ShapeSectionReverseData[i]->MetricOffset = 0;
ShapeSectionReverseData[i]->MetricHeight = 0;
}
for (int l=0; l<MAXPARTS; ++l)
{
for (int k=0; k<MAXSHAPES; ++k)
{
for (int j=0; j<MAXSECTIONS; ++j)
{
PartShapeSection[l][k][j] = new PartShapeSectionRecord;
PartShapeSection[l][k][j]->Area = 0;
}
}
}
LSInputDataRead = false; //default until set
for (int i=0; i<MAXNUMBEROFFRAMES; ++i)
{
FramesData[i] = new FramesDataRecord;
FramesData[i]->FrameNumber = 0;
FramesData[i]->FramePosition = 0;
FramesData[i]->WeightDistr = 0;
FramesData[i]->BuoyancyDistr = 0;
FramesData[i]->SF = 0;
FramesData[i]->BM = 0;
}
}
//---------------------------------------------------------------------------
TLongStrengths::~TLongStrengths() //Destructor
{
for (int k=0; k<MAXLIGHTDISTRITEMS; ++k)
{
delete LightDistr[k];
delete CalcDistr[k];
delete BuoyancyDistr[k];
delete LS1[k];
}
for (int k=0; k<MAXFIXEDLOADS; ++k)
delete FixedLoadPointLoads[k];
for (int k=0; k<MAXSHAPES; ++k)
{
delete ShapeHeader[k];
delete ComponentHeader[k];
delete PartHeader[k];
for (int j=0; j<MAXCOMPONENTSPERPART; ++j)
delete PartData[k][j];
for (int j=0; j<MAXSECTIONS; ++j)
{
delete ShapeSectionHeader[k][j];
for (int i=0; i<MAXOFFSETS; ++i)
{
delete ShapeSectionData[k][j][i];
delete ShapeSectionReverseData[i];
}
}
}
for (int i=0; i<MAXOFFSETS; ++i)
delete ShapeSectionReverseData[i];
for (int i=0; i<MAXNUMBEROFFRAMES; ++i)
delete FramesData[i];
}
//---------------------------------------------------------------------------