Print Page | Close Window

Memory Leak on creating threads

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=24520
Printed Date: 14 November 2024 at 10:11am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Memory Leak on creating threads
Posted By: Kudo Shinya
Subject: Memory Leak on creating threads
Date 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



Replies:
Posted By: agontarenko
Date Posted: 14 November 2024 at 2:45am
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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net