Hello,
i had a memory leak in my program and after a long search tracked it back to PolyVox LargeVolume.
At this point i must say i am pretty new to c++, (Ogre) and PolyVox, so i probably dont understand every design decision. If i'm wrong, maybe just send me a PM and delete this topic to avoid confusion.
i wrote a simple test case:
Code:
for(int i = 0; i < 10000; i++){
PolyVox::Region* region = new PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), PolyVox::Vector3DInt32(31, 31, 31));
PolyVox::LargeVolume<PolyVox::Material8>* volumeData = new PolyVox::LargeVolume<PolyVox::Material8>(*region,0,0,false,(uint16_t)32U);
delete region;
delete volumeData;
}
// memory ~300MB at this point
boost::this_thread::sleep(boost::posix_time::milliseconds(5000));
for(int i = 0; i < 10000; i++){
PolyVox::Region* region = new PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), PolyVox::Vector3DInt32(31, 31, 31));
PolyVox::LargeVolume<PolyVox::Material8>* volumeData = new PolyVox::LargeVolume<PolyVox::Material8>(*region,0,0,false,(uint16_t)32U);
delete region;
delete volumeData;
}
// memory ~600MB at this point
after half of execution memory usage (in window task manager) is at around 300mb, after full execution at 600mb.
i searched around and found in LargeVolume.inl the variable m_pUncompressedBorderData being allocated, but not deallocated during destructor execution.
so i changed the destructor to:
Code:
template <typename VoxelType>
LargeVolume<VoxelType>::~LargeVolume()
{
flushAll();
delete m_pUncompressedBorderData;
}
After that the memory leak is gone, as fas as i can tell.
But like i said above, i dont really know PolyVox well, if this is intentional (maybe needed for any kind of operation) or there is another way to clean up(i didnt find one), let me know.