Memory Leak on creating threads |
Post Reply |
Author | |
Kudo Shinya
Newbie Joined: 11 November 2024 Status: Offline Points: 3 |
Post Options
Thanks(0)
Posted: 11 November 2024 at 2:11am |
CJ: v22.0.0
VisualStudio: 2022 (17.11.5) Windows: 11 I am creating numerous worker threads using _beginthreadex and terminating them with _endthreadex(0) and CloseHandle(). When taking a memory snapshot in Visual Studio, a memory leak of 480 bytes per thread occurs at MyApp.exe!_AFX_THREAD_STATE. The call stack is as follows, confirming that the memory was allocated by the Toolkit during thread creation: kernel32.dll!0x7ff96021257d() MyApp.exe!CXTPSkinManagerDetoursApiHook::ThreadProcHook() - Line 591 MyApp.exe!AfxGetModuleState() - Line 314 MyApp.exe!CThreadLocal<_AFX_THREAD_STATE>CreateObject() - Line 200 MyApp.exe!CThreadLocalObjectGetData() - Line 453 MyApp.exe!CThreadLocal<_AFX_THREAD_STATE>::GetData() - Line 179 MyApp.exe!CThreadLocal<_AFX_THREAD_STATE>::operator _AFX_THREAD_STATE *() - Line 191 It seems that using AfxBeginThread instead of _beginthreadex can avoid this issue My application creates and deletes a very large number of threads, so I cannot overlook this small memory leak. Additionally, the libraries my application depends on also seem to create threads, making it impossible to replace all thread creation with AfxBeginThread. Is there any workaround for this issue? Regars, Shinya
|
|
agontarenko
Admin Group Joined: 25 March 2016 Status: Offline Points: 289 |
Post Options
Thanks(0)
|
Hello Shinya,
Unfortunately it is not clear what exactly is going wrong. Can you please provide more detailed information. If it cannot be re-produced in any of our sample applications provided I would appreciate you sending a sample application so that we could debug it. Regards, Artem Gontarenko |
|
Kudo Shinya
Newbie Joined: 11 November 2024 Status: Offline Points: 3 |
Post Options
Thanks(0)
|
Thank you for your response.
By calling AfxTermThread() at the end of threads created with _beginthreadex and CreateThread, I was able to solve the problem. Thank you. |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |