Results 1 to 5 of 5

Thread: How to compare states of memory in memory leak?

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    How to compare states of memory in memory leak?

    I have recently started studying about the memory leak. And also found that some problems in uTorrent are caused because of memory leaks. Now I wanted to know how can I compare states of memory in memory leak? Since, I am not knowing much about it, please explain me in details. Hoping that someone hanging out there will help me soon.!!

  2. #2
    Join Date
    Feb 2008
    Posts
    121

    Re: How to compare states of memory in memory leak?

    To conclude whether a memory leak took place in a section of code, you can take snapshots of the state of memory prior to and after the section, and compare the two states with _CrtMemDifference :
    Code:
    _CrtMemCheckpoint (& S1);
     / / Memory allocations take place here
     _CrtMemCheckpoint (& S2);
    
     if (_CrtMemDifference (& s3, & s1, & s2))
        _CrtMemDumpStatistics (& S3);

  3. #3
    Join Date
    Feb 2008
    Posts
    137

    Re: How to compare states of memory in memory leak?

    Another modus operandi for detecting memory leaks is to take snapshots of the state of the application memory in certain key points. The CRT provides a type of structure, _CrtMemState, which you can use to store a snapshot of the memory :
    _CrtMemState S1, s2, s3;

  4. #4
    Join Date
    Oct 2008
    Posts
    180

    Re: How to compare states of memory in memory leak?

    To take a snap of the state of memory at a prearranged point, pass a structure to function _CrtMemState _CrtMemCheckpoint . This function fills the arrangement with a snapshot of the current state of memory :
    • _CrtMemCheckpoint (& S1);
    You can dump the contents of a structure _CrtMemState at any point in passing the structure to function _CrtMemDumpStatistics :
    • _CrtMemDumpStatistics (& S1);

  5. #5
    Join Date
    Feb 2008
    Posts
    180

    Re: How to compare states of memory in memory leak?

    As its name suggests, _CrtMemDifference compares two memory states (s1 and s2) and produces a result (s3), which corresponds to the difference between the two states. By placing calls to _CrtMemCheckpoint at the beginning and the end of your program, then using _CrtMemDifference to compare the results, you have another way to search for memory leaks. If a leak is detected, you can use calls to _CrtMemCheckpoint to split your program and locate the leak with a binary search technique.

Similar Threads

  1. svchost.exe consumes CPU and Memory - Memory Leak?
    By Chad Gross in forum Windows XP Support
    Replies: 1
    Last Post: 25-03-2013, 12:46 PM
  2. Memory leak in Firefox 3.6.11
    By Eric Banadinovich in forum Technology & Internet
    Replies: 4
    Last Post: 19-04-2011, 07:57 PM
  3. Memory Leak 60 to 30-40 fps in Crysis 2
    By Krisoijn in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 25-03-2011, 10:16 PM
  4. Memory leak issue with New PC
    By Alchmey in forum Windows Software
    Replies: 2
    Last Post: 23-10-2008, 08:01 PM
  5. Memory leak in services.exe
    By JuanD in forum Windows Server Help
    Replies: 2
    Last Post: 28-04-2008, 07:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,624,635.43121 seconds with 17 queries