Python scripting memory leak
Python scripting memory leak
(OP)
I wrote a script to propagate cracks through material and I found a peculiar memory leak.
For instance I delete existing seams like this:
for e in aPart.edges:
mModel.rootAssembly.engineeringFeatures.
deleteSeam(regions=regionToolset.Region(
edges=aPart.edges.findAt((e.pointOn[0], ))))
But this puny codepiece causes .cae file to grow ~50 KB whenever executed.
After 100 extensions .cae grows to a few MB irreversibly - I deleted parts, assembly, cracks (basicaly everything that is deletable througs ABAQUS GUI) saved it under a new name and still ended up with this huge .cae.
I use ABAQUS 6.6-1
For instance I delete existing seams like this:
for e in aPart.edges:
mModel.rootAssembly.engineeringFeatures.
deleteSeam(regions=regionToolset.Region(
edges=aPart.edges.findAt((e.pointOn[0], ))))
But this puny codepiece causes .cae file to grow ~50 KB whenever executed.
After 100 extensions .cae grows to a few MB irreversibly - I deleted parts, assembly, cracks (basicaly everything that is deletable througs ABAQUS GUI) saved it under a new name and still ended up with this huge .cae.
I use ABAQUS 6.6-1





RE: Python scripting memory leak
The interesting part is than under v6.4 this problem did not occur. I could run the same model generation script repeatedly without any memory leak.
Also, in v6.5 when generating 2D parts with holes, CAE takes a huge amount of memory for no reason, but this does not happen in 6.6.
I think the problem is objects remain referenced internally by CAE, for some reason, and the occupied memory cannot be collected.
RE: Python scripting memory leak
The way the cae database is architected is such that deleting objects does not necessarily free the memory allocated in the database for those objects - it just marks those objects as "deleted" and they are no longer referenced by anything. (This is the same behavior as a lot of databases e.g. Microsoft Office pst files - and the reason why they provide a "compact now" facility)
Anyway, doing a save as only copies the "live" objects, so the resulting .cae file will be much smaller.
RE: Python scripting memory leak
RE: Python scripting memory leak
Probably, the objects defining the model still remain referenced in CAE internally, even after using "del object_reference", and therefore the memory cannot be freed.
RE: Python scripting memory leak
This is known issue and there is a patch under development to try and fix this problem in Python 2.5.
One way to possible workaround is to run python as separate child process for one iteration and kill sometimes it to free memory to the operating system.