Как решить проблему утечки памяти с моей функцией экспорта данных? - PullRequest
0 голосов
/ 08 октября 2019

Я запускаю этот код {в цикле for}, который состоит из вспомогательных функций, созданных коммерческой компанией Remcom. Когда я экспортирую свои наборы данных, моя оперативная память медленно заполняется, и мне приходится закрывать программу (XFdtd), перезапускать ее и перезапускать функцию экспорта в том месте, где я остановился. Что-то не так с моим кодом или оператором, который я могу включить для очистки кучи после каждой итерации? Это моя функция:

function exportBandE(simId,name)
{
/////////////////////////////////////////////////////////////////////////////////////////////
// Now lets try and export a result or numerous results and mimic the export given by the GUI
// will need projectId, simulationId, and probably runId
var fullPathB = "E:/ACCRE/5652/Bfield/" + name + ".mat";
var fullPathE = "E:/ACCRE/5652/Efield/" + name + ".mat";
var simulationId = App.getActiveProject().getSimulation(simId)
var projectId = simulationId.getProjectId();
//Load B data from the simulation
var resultBrowser = App.getResultBrowser();

resultBrowser.addProject(App.getActiveProject().getProjectDirectory())
var Qx = new ResultQuery();
Qx.projectId = projectId;
Output.println(projectId)
Qx.simulationId = simId;
Qx.runId = simulationId.getRunId( 0 );
Qx.sensorType = ResultQuery.SolidVolumeSensor;
Qx.sensorId = Qx.getAvailableSensorIds()[ 0 ];
Qx.timeDependence = ResultQuery.SteadyState;
Qx.resultType = ResultQuery.B;
Qx.fieldScatter = ResultQuery.TotalField;
Qx.dataTransform = ResultQuery.NoTransform;
Qx.surfaceInterpolationResolution = ResultQuery.NoInterpolation;
Qx.setDimensionRange( "Frequency", 0, -1 );
Qx.setDimensionRange("X",0,-1);
Qx.setDimensionRange("Z",0,-1);
Qx.setDimensionRange("Y",0,-1);

//BX
Qx.resultComponent = ResultQuery.X;
Qx.complexPart = ResultQuery.RealPart;
var xds = new ResultDataSet( "Bx field real" );
xds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var xdsi = new ResultDataSet( "Bx field complex" );
xdsi.setQuery(Qx);

//BY
resultBrowser.FullRefreshType;
Qx.resultComponent = ResultQuery.Y;
Qx.complexPart = ResultQuery.RealPart;
var yds = new ResultDataSet( "By field real" );
yds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var ydsi = new ResultDataSet( "By field complex" );
ydsi.setQuery(Qx);

var exportedFile = new File(fullPathB);
exportedFile.open(IODevice.WriteOnly);
DataSetExportUtility.writeMatlabHeader(exportedFile);

//You can then pass exportedFile as the first parameter to the addMatlabVariable function.
DataSetExportUtility.addMatlabVariable(exportedFile, "BxField", false, xds,xdsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "ByField", false, yds,ydsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "Frequency", false, xds.getDimension("Frequency"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "xdim", true, xds.getDimension("X"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "ydim", true, xds.getDimension("Y"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "zdim", true, xds.getDimension("Z"),false );
//DataSetExportUtility.addMatlabVariable(exportedFile, "BzField", false, zds,zdsi );
exportedFile.close();

/////////////////
var Qx = new ResultQuery();
Qx.projectId = projectId;
Output.println(projectId)
Qx.simulationId = simId;
Qx.runId = simulationId.getRunId( 0 );
Qx.sensorType = ResultQuery.SolidVolumeSensor;
Qx.sensorId = Qx.getAvailableSensorIds()[ 0 ];
Qx.timeDependence = ResultQuery.SteadyState;
Qx.resultType = ResultQuery.E;
Qx.fieldScatter = ResultQuery.TotalField;
Qx.dataTransform = ResultQuery.NoTransform;
Qx.surfaceInterpolationResolution = ResultQuery.NoInterpolation;
Qx.setDimensionRange( "Frequency", 0, -1 );
Qx.setDimensionRange("X",0,-1);
Qx.setDimensionRange("Z",0,-1);
Qx.setDimensionRange("Y",0,-1);

//EX
Qx.resultComponent = ResultQuery.X;
Qx.complexPart = ResultQuery.RealPart;
var xds = new ResultDataSet( "Ex field real" );
xds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var xdsi = new ResultDataSet( "Ex field complex" );
xdsi.setQuery(Qx);

//EY
resultBrowser.FullRefreshType;
Qx.resultComponent = ResultQuery.Y;
Qx.complexPart = ResultQuery.RealPart;
var yds = new ResultDataSet( "Ey field real" );
yds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var ydsi = new ResultDataSet( "Ey field complex" );
ydsi.setQuery(Qx);

//EZ
Qx.resultComponent = ResultQuery.Z;
Qx.complexPart = ResultQuery.RealPart;
var zds = new ResultDataSet( "Ez field real" );
zds.setQuery(Qx);

Qx.complexPart = ResultQuery.ImaginaryPart;
var zdsi = new ResultDataSet( "Ez field complex" );
zdsi.setQuery(Qx);

// add to already existing matlab file
var exportedFile = new File(fullPathE);
exportedFile.open(IODevice.WriteOnly);
DataSetExportUtility.writeMatlabHeader(exportedFile);
DataSetExportUtility.addMatlabVariable(exportedFile, "ExField", false, xds,xdsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "EyField", false, yds,ydsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "EzField", false, zds,zdsi );
DataSetExportUtility.addMatlabVariable(exportedFile, "Frequency", false, xds.getDimension("Frequency"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "xdim", true, xds.getDimension("X"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "ydim", true, xds.getDimension("Y"),false );
DataSetExportUtility.addMatlabVariable(exportedFile, "zdim", true, xds.getDimension("Z"),false );
exportedFile.close();
gc();
...