In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "C# memory leak problem Analysis". In daily operation, I believe many people have doubts about C# memory leak problem analysis. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "C# memory leak problem Analysis"! Next, please follow the editor to study!
Today, when I was reading a foreign technical article, I found that someone was studying this problem! He offered a solution. First of all, to introduce him, the operating system assigns a data structure called TIB (Thread Information Block) or TEB (Thread Enviroment BLock) to each thread running in the system. It records all the information related to a thread. Of course, it includes thread-related stack address information. The top of the stack and the base address of the stack are stored in the 4 and 8 positions of the FS register, respectively. So he realizes the method of judging whether the pointer is a stack pointer or a heap pointer through embedded assembly. The code is as follows:
Bool IsMemoryOnStack (LPVOID pVoid) {LPVOID dwStackTop = 0; LPVOID dwStackLowCurrent = 0; _ _ asm {mov EAX, FS: [4] mov dwStackTop, eax mov EAX, FS: [8] mov dwStackLowCurrent, eax} if (pVoid)
< = dwStackTop && pVoid >= dwStackLowCurrent) {/ / The memory lie between the stack top and stack commited. Return true;} / / Pointer dosen't point to the stack return false;}
Now you just need to change the function that CTest may cause memory leak to the following, and you can solve the problem:
CTest (CTest* & t) {this- > xlocate-> getX (); if (! IsMemoryOnStack (t)) {delete t0;}}
The advantage of using a pointer reference here is to prevent the user from continuing to access the pointer's memory after the pointer's memory is freed.
At this point, the study of "Analysis of C# memory leak" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.