I am working with Visual C++. I have the source code of a library, call it Lib. The library is made of a .lib and a .dll. I link the .lib in my main project statically and put the .dll in the directory where there is the executable. I allocate some memory in the main project (that is, load a file into memory), pass it to an object of the .dll to construct it and, when the program exits, the object call delete on that memory.
It seems to work, but i am not sure. What concerns me is that i allocate memory in my main project and de-allocate memory in a .dll. Are they on the same heap?
That works as long as you link to shared MSVC libraries with the memory allocation runtime. Then EXE and DLL share the same heap.
If you break this dependency, the heap will no longer be shared and deleting the object in the different heap will ruin the app.