我在我的函数中使用了 GetModuleHandle。每次我执行操作时都会调用该函数。我想知道该函数是否被一次又一次地调用,GetModuleHandle 是否会导致任何句柄泄漏(堆栈溢出或内存泄漏或其他任何情况)。我实际上知道它何时被调用以及何时达到断点。但我无法确定 GetModuleHandle 是否导致任何句柄泄漏。谁能帮我解答一下。谢谢,下面是在操作中重复调用的函数。
void Myfunc(int iCtrlID) { HINSTANCE hinst = GetModuleHandle("r.dll");
s.LoadString(hinst, iCtrlID); // 更多代码在这里 // }
最佳答案
来自documentation :
The GetModuleHandle function returns a handle to a mapped module without incrementing its reference count. Therefore, use care when passing the handle to the FreeLibrary function, because doing so can cause a DLL module to be unmapped prematurely.
阅读:如果您尝试释放 handle ,您会崩溃。 不要清理,你会没事的。
关于visual-c++ - GetModuleHandle 函数是否会导致 VC++ 中的任何泄漏(堆栈溢出和内存泄漏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2148935/