简体   繁体   中英

Releasing memory for DLL dynamically linked to CRT heap with the same version after calling FreeLibrary

From what I've read so far, it is generally recommended to use std::shared_ptr , process heap or a wrapper function in the DLL itself to release memory allocated in the DLL. This is, however, built on the assumption that the application and the DLL may not be sharing the same CRT version which can potentially cause the program to crash when the application releases the memory that the DLL allocated.

If a DLL is linked explicitly to the application and both are dynamically linked to CRT heap with a guarantee that they have the same CRT version, is it safe to allocate/release memory as per normal? (ie just the usual new / delete without any extra stuff)

Also, by extension, is it safe to release memory that is allocated by the DLL in the application after the DLL has been released? (ie after calling FreeLibrary )

In addition to version, it also matters if the main program and the DLL share the same copy of the heap.

In Visual Studio, to ensure that, you have to specify in the project config: Runtime Library = Multi-threaded DLL or Multi-threaded Debug DLL (/MD or /MDd) - in both DLL project and the main program project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM