Note that there are some explanatory texts on larger screens.

plurals
  1. POCleanup shared memory with vector inside
    text
    copied!<p>I'm using <strong>boost::interprocess::managed_shared_memory</strong> to share some data between different processes and was wondering how cleanup works. In general, I have to following situation:</p> <pre><code>boost::interprocess::managed_shared_memory *sharedSegment; typedef boost::interprocess::allocator&lt; MyObject, boost::interprocess::managed_shared_memory::segment_manager&gt; SharedMemoryAlloc; typedef boost::interprocess::vector&lt;MyObject, SharedMemoryAlloc&gt; 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-&gt;get_segment_manager()); sVec = sharedSegment-&gt;construct&lt;SharedVector&gt;("MyVector")( (*allocToSharedSegment) ); delete allocToSharedSegment; // Fill sVec, do some computation etc.. // Start cleanup //sVec-&gt;clear(); delete sharedSegment; boost::interprocess::shared_memory_object::remove("TEST"); </code></pre> <p>Since I call boost::interprocess::shared_memory_object::remove("TEST"); I always thought, that everything inside the memory is deleted anyway, and therefore I do not have to take care of sVec. But Visual Leak Detector told me, there were some memory leaks at this point. If I clear the vector before deleting the shared memory, everything works fine. Could it be, that sVec holds pointer internally and therefore I have to call clear()?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload