Hi Peter, the short answer is that you can't free this allocated memory. This is a known issue with Sim4Life's Python API. What happens is that the postprocessing algorithms instantiated by the Python functions create some C++ data objects to hold the actual bulk of the data: the same memory blocks can be accessed by Sim4Life's C++ code, or by the user's Python script. Unfortunately, deleting the Python objects does not always deallocate the C++ data objects. This can result in memory leaks, similar to what you described.
The workaround is to not allocate too much memory in the first place, by reusing existing algorithms instead of creating new ones. It is possible to only change the inputs of an algorithm and update it. Here is an example that exports the E fields of each port of a multiport simulation as Matlab files, but only allocate memory for one port:
# Creating the analysis pipeline
# Adding a new EmMultiPortSimulationExtractor
simulation = document.AllSimulations["Patch Antenna - Multiport"]
em_multi_port_simulation_extractor = simulation.Results()
#Create the postprocessing pipeline once
output_port = em_multi_port_simulation_extractor.Outputs[0]
# Adding a new EmPortSimulationExtractor
em_port_simulation_extractor = analysis.extractors.EmPortSimulationExtractor(inputs=[output_port])
em_port_simulation_extractor.UpdateAttributes()
document.AllAlgorithms.Add(em_port_simulation_extractor)
# Adding a new EmSensorExtractor
em_sensor_extractor = em_port_simulation_extractor["Overall Field"]
document.AllAlgorithms.Add(em_sensor_extractor)
# Adding a new MatlabExporter
inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
matlab_exporter = analysis.exporters.MatlabExporter(inputs=inputs)
matlab_exporter.UpdateAttributes()
document.AllAlgorithms.Add(matlab_exporter)
# Update the postprocessing pipeline for each port
for i, output_port in enumerate(em_multi_port_simulation_extractor.Outputs):
em_port_simulation_extractor.raw.SetInputConnection(0, output_port.raw) # this is the main "trick"
em_port_simulation_extractor.UpdateAttributes()
inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
matlab_exporter.FileName = u"D:\\temp\\ExportedData_{}.mat".format(i)
print matlab_exporter.FileName
matlab_exporter.UpdateAttributes()
matlab_exporter.Update()