That isn't the case for shared memory if there are other processes attached to it. It is probably reference counted. As the documentation says, unless the QSharedMemory destructor is called (decrementing the reference count), you cannot be guaranteed that the OS will release the memory. Heap that is freed when a process exits is simply freed without calling any destructors. That's why you can have a program with a memory leak and have all the leaked memory freed on exit.Since heap-allocated memory is freed on program exit there's no need for explicit free().
i don't know what the problem is with your program. Maybe your choice of "foo" as the key? Pretty common thing for a programmer to use as a name for testing purposes.
Bookmarks