Boost logo

Boost Users :

Subject: [Boost-users] managed_shared_memory memory leak(?)
From: Michael Herrmann (mherrmann.at_at_[hidden])
Date: 2012-04-25 06:35:08


Hello everyone,

the following trivial example highlights a memory leak according to MSVC
2010. Does anybody know why this is and how it can be avoided?

     // The following three directives are required for MSVC's automatic
memory
     // leak detection.
     #define _CRTDBG_MAP_ALLOC
     #include <stdlib.h>
     #include <crtdbg.h>

     #include <boost/interprocess/managed_shared_memory.hpp>

     int main(int argc, char *argv[])
     {
         {
             using namespace boost::interprocess;
             static const char* shMemIdentifier = "MySharedMemory";
             struct ShMemCleaner {
                 ShMemCleaner() {
shared_memory_object::remove(shMemIdentifier); }
                 ~ShMemCleaner()
{shared_memory_object::remove(shMemIdentifier); }
             } cleaner;

             // Create a new segment with given name and size
             managed_shared_memory segment(create_only, shMemIdentifier,
1024);

             int* intInShMem = segment.construct<int>("myInt")(2);
             segment.destroy<int>("myInt");
         }
         _CrtDumpMemoryLeaks();
     }

Thank you very much!

Best,
Michael


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net