Closed xiangtaoxu closed 2 years ago
Hi,
With CloudComPy, the Python garbage collector is not connected to CloudCompare C++ objects. You should explicitly delete the CloudCompare entities you no longer need with cc.deleteEntity(entity)
.
import sys, os, gc, psutil
# initialize CCP
os.environ["_CCTRACE_"]="OFF" # this line has to be called before import cloudComPy
# load CloudCompy
import cloudComPy as cc
def f(cloud):
# do nothing, return a tuple
return (0,[cloud])
cc.initCC()
process = psutil.Process(os.getpid())
mem_start = process.memory_full_info().rss
cloud = cc.loadPointCloud('./memory_test.pcd')
print('input cloud memory usage:', process.memory_full_info().rss - mem_start)
for i in range(100):
mem_start = process.memory_full_info().rss
res = f(cloud)
print(f'iteration {i}, f added memory: ',process.memory_full_info().rss - mem_start)
mem_start = process.memory_full_info().rss
res = cc.ExtractConnectedComponents(
clouds=[cloud],
octreeLevel=10,
minComponentSize=1000,
maxNumberComponents=100)
# -----------------------------------------------------------
# do something with the components,
# then delete the components when you don't need them any more.
components = res[1]
for comp in components:
cc.deleteEntity(comp)
# be sure to have no more Python variable referencing the deleted items
components = None
res = None
# -----------------------------------------------------------
print(f'iteration {i}, ExtractConnectedComponents added memory: ',process.memory_full_info().rss - mem_start)
After 3 iterations, memory is stable. Regards,
Paul
That makes perfect sense. Thanks so much!
Hi, I think there is a memory leak problem in the cc.ExtractConnectedComponents function.
I attach a simple script to illustrate the problem. Basically, the script read a point cloud (roughly 52 MB) and called the ExtractConnectedComponents function 5 times. After each call, roughly 45MB is added to the memory. This is becoming an issue for our codes which calls ExtractConnectedComponents hundreds to thousands of times for some big dataset.
memory_test.zip
I know memory bugs are usually very tricky... So hopefully you can help to look into this. Thanks in advance!