开发者

Resource leaks when using a VCL (C++Builder) DLL from .NET

开发者 https://www.devze.com 2022-12-17 18:46 出处:网络
I have a DLL that\'s written in C++Builder (2006), and I\'m invoking a single function in the DLL from a .NET application.

I have a DLL that's written in C++Builder (2006), and I'm invoking a single function in the DLL from a .NET application.

The problem is, when I close the .NET application (and the DLL gets detached from it) I get a CodeGuard error saying that it detected resource leaks (and I see the leaks in the CodeGuard log file). I also see the LoaderLock MDA pop up in Visual Studio when freeing the DLL (probably for the same reason?).

Now, I'm 99% certain that I'm freeing all the memory I'm using in the DLL function. In fact, I tried building a dummy DLL with an identically-named function that does absolutely nothing, and still got resource leaks when the DLL is unloaded from the .NET application.

My only suspicion at this point is the fact that I'm using VCL built into the DLL. Is there some uninitialization function that I need to call explicitly when detaching from the DLL? What could be going on?

p.s. The memory addresses from the call stack given in the CodeGuard log file see开发者_开发技巧m to be well beyond anything I see in my Map file.


This sounds extremely familiar to an issue I chased for a while with Delphi. I asked the question on SO some while back. I tracked it down at least partially to threadvar (thread local storage) memory that is not freed. I believe that C++Builder uses the same VCL components as Delphi, so it could be the same issue. Unfortunately, I did not find any satisfactory solution other than to not unload the DLL if it was ever going to be loaded again in the future.

0

精彩评论

暂无评论...
验证码 换一张
取 消