CloudCompare-PythonPlugin icon indicating copy to clipboard operation
CloudCompare-PythonPlugin copied to clipboard

How to manage memory?

Open tpwrules opened this issue 3 years ago • 4 comments

I have a simple script which loads a bunch of files using pycc.FileIOFilter.LoadFromFile, but I cannot figure out how to destroy the ccHObjects 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.

tpwrules avatar Sep 20 '21 19:09 tpwrules

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.

tmontaigu avatar Sep 21 '21 08:09 tmontaigu

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.

tpwrules avatar Sep 21 '21 19:09 tpwrules

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

tmontaigu avatar Sep 21 '21 20:09 tmontaigu

Fixing this required a bit more work that I initially thought, but it should work now.

I expect some other similar case to exist

tmontaigu avatar Sep 22 '21 09:09 tmontaigu