Windbg lab-lab3, memory

Source: Internet
Author: User

Original article address:Http://blogs.msdn.com/ B /tess/archive/2008/02/15/net-debugging-demos-lab-3-memory.aspx

Procedure:

1. pressure generation: tinyget-SRV: localhost-Uri:/buggybits/links. aspx-loop: 4000

2. Observe the output of taskmgr. The memory of w3wp increases by about 100 mb per second.

3. capture an hang dump when the memory reaches about MB.

4. Because this is a memory problem, we should first check the GC heap situation and run the command :! Eeheap-GC. The result is as follows:

GC heap size 0x2b307720 (724596512)

Because dump has a total of 870 m, and GC occupies around M, our focus is on the analysis of managed memory.

5. Check the overall heap status and run it! Dumpheap-Stat. The result is as follows:

790fd8c4 49787 721599752 system. String

Well, in the M managed memory, string occupies the vast majority.

6. Let's take a look at the string situation. According to the 2/8 principle, there may be many strings of the same size. Here we will filter the strings of a size greater than 10 KB and run the following command :! Dumpheap-MT 790fd8c4-min 10000

0331d6dc 790fd8c4 20020
03322534 790fd8c4 20020
0332738c 790fd8c4 20020
0332c1e4 790fd8c4 20020
0333103c 790fd8c420020

Most of them are 20 k strings. You can find one string at will. We need to see who assigned it.

7. Run! Gcroot 0331d6dc. The result is as follows:

Scan thread 16 osthread 318
Scan thread 18 osthread c38
Scan thread 19 osthread A40
Scan thread 20 osthread c00
Scan thread 24 osthread 998
Scan thread 14 osthread 4cc
Finalizer queue: Root: 0331d6b8 (Link)->
0331d6c8 (system. Text. stringbuilder)->
0331d6dc (system. String)

In thread 14, Link References this string. And we can see that link is in finalizer queue.

8. View finalizequeue. The output is as follows:

057e0bcc 35998 575968 Link

There are a total of 35998 link objects. Because the object exists in finalizequeue, the Finalize method must be displayed.

9. view this method,CodeAs follows:

~ Link ()
{
// Some long running operation when cleaning up the data
Thread. Sleep (5000 );
}

10. Change the direction and check the link object in Step 7 above ,! Do 0331d6b8. The output result is as follows:

mT field offset type vt attr value name
790fdc5c 4000006 4... ext. stringbuilder 0 instance 0331d6c8 URL
790fd8c4 4000007 8 system. string 0 instance 029bb0b8 name
check the first URL object and run it! Do 0331d6c8:

MT field offset type vt attr Value Name
791016bc 40000b1 8 system. intptr 1 instance dc1d8 m_currentthread
79102290 40000b2 C system. int32 1 instance 2147483647 m_maxcapacity
790fd8c4 40000b3 4 system. String 0 instance 0331d6dc m_stringvalue

Pay attention to the m_stringvalue In the last line, and compare it with Step 7! Gcroot input.

From this we can see that link contains a stringbuilder, and stringbuilder contains a 20 k string.

11. Check the Code:

Public Link (string name, string URL)
{
This. Name = Name;
This. url. append (URL );
}
We can see that the link object constructor references strings.

12. Looking back at Step 9 above, link intelligently implements the Finalize method, but the execution time of this method is too long (5 seconds here), resulting in garbage collection, the object cannot be recycled. Because link references the string URL, the corresponding string cannot be recycled. In this way, the memory will increase rapidly.

 

Over

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.