2

boost::interprocess::managed_shared_memoryを使用して、異なるプロセス間でデータを共有していますが、クリーンアップがどのように機能するのか疑問に思っていました。一般的に、私は次のような状況にならなければなりません:

boost::interprocess::managed_shared_memory *sharedSegment;
typedef boost::interprocess::allocator< MyObject, boost::interprocess::managed_shared_memory::segment_manager>  SharedMemoryAlloc;
typedef boost::interprocess::vector<MyObject, SharedMemoryAlloc> SharedVector;
SharedVector *sVec;
unsigned int size;

// Do some other stuff and determine correct size
sharedSegment= new boost::interprocess::managed_shared_memory(boost::interprocess::create_only, "TEST", size);
SharedMemoryAlloc *allocToSharedSegment = new SharedMemoryAlloc(sharedSegment->get_segment_manager());
sVec = sharedSegment->construct<SharedVector>("MyVector")( (*allocToSharedSegment) );
delete allocToSharedSegment; 

// Fill sVec, do some computation etc..

// Start cleanup
//sVec->clear(); 
delete sharedSegment;

boost::interprocess::shared_memory_object::remove("TEST"); 

boost::interprocess::shared_memory_object::remove("TEST"); を呼び出すので とにかくメモリ内のすべてが削除されるといつも思っていたので、sVecの世話をする必要はありません。しかし、Visual Leak Detector によると、この時点でいくつかのメモリ リークが発生しています。共有メモリを削除する前にベクトルをクリアすると、すべて正常に動作します。sVec はポインタを内部的に保持しているため、clear() を呼び出さなければならないのでしょうか?

4

0 に答える 0