CloudCompare-PythonPlugin
CloudCompare-PythonPlugin copied to clipboard
How to manage memory?
I have a simple script which loads a bunch of files using pycc.FileIOFilter.LoadFromFile
, but I cannot figure out how to destroy the ccHObject
s that it returns. Thus, the loaded files are simply leaked and CloudCompare eventually crashes because it runs out of memory.
I also cannot figure out how to remove objects that have been added to the DB, or how (or if) I should destroy the clouds returned from methods like resampleCloudSpatially
, partialClone
, etc.
I think there needs to be a section on memory management in the documentation, and perhaps some additional methods added if necessary. I don't think it's possible to correctly manage memory right now.
The memory management is the same as regular Python so you should not have to care about about deleting/destroying objects.
The fact that pycc.FileIOFilter.LoadFromFile
leaked memory was due to leftovers from a time where memory management was unclear with the DB.
And the removeFromDB
method was added to the ccGUIPythonInstance
API.
The master branch contains the fixes.
Memory management still does not quite work with ccHObject
. Consider the following code:
file = pycc.FileIOFilter.LoadFromFile(path, params)
obj = file.getChild(0)
del file
subsampled = cccorelib.CloudSamplingTools.resampleCloudSpatially(obj, 0.001, mod_params)
CloudCompare crashes at the last line because del file
destroyed the child obj
while Python still had a reference to it.
the plugin is still very experimental so not all things are not going to work flawlessly.
This case may be fixable
In the meantime, you can just remove that del
Fixing this required a bit more work that I initially thought, but it should work now.
I expect some other similar case to exist