A technique is disclosed for detecting a memory leak. A request to allocate or deallocate memory is received. In a memory leak table that is bounded in size, an entry that is associated with a call path with which the request is associated is accessed. The entry in the memory leak table is updated. The entry is accessed and a value stored in the entry is read. It is determined if the value indicates that a memory leak may be present.
|
1. A method of detecting a memory leak, comprising:
receiving a request to allocate or deallocate memory;
accessing in a memory leak table that is bounded in size an entry that is associated with a call path with which the request is associated;
updating the entry in the memory leak table;
accessing the entry and reading a value stored in the entry; and
determining if the value indicates that a memory leak may be present.
28. A system for detecting a memory leak, comprising:
a processor configured to:
receive a request to allocate or deallocate memory;
access in a memory leak table that is bounded in size an entry that is associated with a call path with which the request is associated;
update the entry in the memory leak table; and
access the entry and read a value stored in the entry; and
determine if the value indicates that a memory leak may be present; and
a memory that is coupled with the processor and configured to store the memory leak table.
29. A computer program product for detecting a memory leak, the computer program product being embodied in a computer readable storage medium and comprising computer instructions for:
receiving a request to allocate or deallocate memory;
accessing in a memory leak table that is bounded in size an entry that is associated with a call path with which the request is associated;
updating the entry in the memory leak table;
access the entry and read a value stored in the entry; and
determine if the value indicates that a memory leak may be present.
2. The method of
3. The method of
5. The method of
6. The method of
7. The method of
8. The method of
9. The method of
10. The method of
11. The method of
12. The method of
13. The method of
14. The method of
15. The method of
16. The method of
18. The method of
19. The method of
20. The method of
21. The method of
22. The method of
23. The method of
24. The method of
26. The method of
determining a current value of the count; and
in the event the count is greater than a prescribed threshold, concluding that a memory leak may be present.
27. The method of
30. The system of
31. The system of
32. The system of
33. The system of
34. The computer program product of
35. The computer program product of
36. The computer program product of
37. The computer program product of
|
The present invention relates generally to computer environments. More specifically, memory leak detection is disclosed.
Memory leaks can occur when a program allocates memory but does not later deallocate the memory. Typical conventional memory leak detection systems sample a processor running the program at some rate, such as 100 samples per second. When a memory allocation is detected in a sample, a memory allocation record is stored. When a memory deallocation is detected, a corresponding memory allocation record is deleted. Memory allocation records can be analyzed for memory leaks. One problem with this method is it can consume an increasing amount of runtime memory. Another problem with this method is the sampling may miss some call paths. Also, a special build is typically required for the process. It would be desirable to have a more reliable and efficient way to perform memory leak detection.
Various embodiments of the invention are disclosed in the following detailed description and the accompanying drawings.
The invention can be implemented in numerous ways, including as a process, an apparatus, a system, a composition of matter, a computer readable medium such as a computer readable storage medium or a computer network wherein program instructions are sent over optical or electronic communication links. In this specification, these implementations, or any other form that the invention may take, may be referred to as techniques. In general, the order of the steps of disclosed processes may be altered within the scope of the invention.
A detailed description of one or more embodiments of the invention is provided below along with accompanying figures that illustrate the principles of the invention. The invention is described in connection with such embodiments, but the invention is not limited to any embodiment. The scope of the invention is limited only by the claims and the invention encompasses numerous alternatives, modifications and equivalents. Numerous specific details are set forth in the following description in order to provide a thorough understanding of the invention. These details are provided for the purpose of example and the invention may be practiced according to the claims without some or all of these specific details. For the purpose of clarity, technical material that is known in the technical fields related to the invention has not been described in detail so that the invention is not unnecessarily obscured.
Detecting a memory leak is disclosed. A memory leak table may be used to detect a memory leak. When a memory allocation or deallocation request is received, an entry associated with a call path is updated in the memory leak table. In one embodiment, there is an entry for each unique call path. In one embodiment, the memory leak table is bounded in size by using a hash function to map a call path to a table entry. A memory leak can be detected by analyzing the memory leak table entries during or after program execution.
In one embodiment, entry 220 is unique to the call path from which memory block 204 was allocated. Each time this call path is called and a new memory block is allocated, entry 220 is updated. Entry 220 includes information that tracks memory requests resulting from that call path. Such information can be stored in numerous ways.
The stack pointers included in entry 220 in some embodiments comprise addresses in the stack of function calls in the call path associated with entry 220. For example, referring back to
In some embodiments, there is an entry in memory leak table 208 for each unique call path. Bounding the size of memory leak table 208 may result in multiple entries mapping to the same row in memory leak table 208 in some embodiments. For example, a hash function may be performed on call path parameters, and the hash result may be used to determine a row in memory leak table 208. To bound the size of the table, in some embodiments the modulo base N of the hash result may be taken, for example, where N is the number of rows in the memory leak table. In such an embodiment, even if each call path associated with a memory allocation or deallocation were to yield a unique hash result, the result of the modulo base N of the respective hash results for two unique call paths may be the same. In such embodiments, a provision must be made for storing in a single row of the memory leak table a separate entry such as entry 220 for each of two or more unique call paths. In some embodiments this is achieved by configured each row of the memory leak table to store a linked list of entries, each entry being associated with a unique call path.
Once a row in the memory leak table is accessed, it is determined whether the call path matches that of an existing entry (366). For example, zero, one or multiple entries may be associated with the row. In one embodiment, the hash value calculated in step 354 is used as a key to determine if there is an existing entry in the row that is associated with the call path. In one embodiment, multiple entries form a linked list that is associated with the row, as shown in
As such, a memory leak table can be used to detect one or more memory leaks in an application. For example, entries in the memory leak table can be analyzed. In one embodiment, any entries that have nonzero count values after a program is finished executing may indicate a memory leak. By storing stack pointers in the entries of the memory leak table, the call paths can be analyzed to determine the source of memory leaks in the program. Allocated memory blocks can also be analyzed. By storing in each memory block header a pointer to an entry in the memory leak table, the functions that allocated the memory block can be determined. This may be useful for analyzing whether a process is allocating more memory than expected.
Although the foregoing embodiments have been described in some detail for purposes of clarity of understanding, the invention is not limited to the details provided. There are many alternative ways of implementing the invention. The disclosed embodiments are illustrative and not restrictive.
Patent | Priority | Assignee | Title |
10963374, | Aug 24 2011 | Microsoft Technology Licensing, LLC | Memory allocation analysis |
8429620, | Jun 27 2008 | International Business Machines Corporation | Memory leak diagnosis |
8881107, | Aug 24 2011 | Microsoft Technology Licensing, LLC | Automatic memory leak detection |
8918616, | Aug 24 2011 | Microsoft Technology Licensing, LLC | Memory allocation analysis |
8959490, | Oct 04 2007 | International Business Machines Corporation | Optimizing heap memory usage |
9141510, | Aug 24 2011 | Microsoft Technology Licensing, LLC | Memory allocation tracking |
9940068, | Dec 11 2015 | Wind River Systems, Inc. | Device and method for determining memory leaks |
Patent | Priority | Assignee | Title |
5842019, | Sep 13 1996 | Parasoft Corporation | Method and system for dynamically detecting leaked memory space in a computer program |
6658652, | Jun 08 2000 | GOOGLE LLC | Method and system for shadow heap memory leak detection and other heap analysis in an object-oriented environment during real-time trace processing |
20040123038, | |||
20050076184, | |||
20050204342, |
Executed on | Assignor | Assignee | Conveyance | Frame | Reel | Doc |
Apr 21 2004 | RAUT, DEVENDRA | ALCATEL IP NETWORKS, INC | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 015266 | /0448 | |
Apr 23 2004 | Alcatel IP Networks, Inc. | (assignment on the face of the patent) | / | |||
Jan 30 2013 | Alcatel-Lucent USA Inc | CREDIT SUISSE AG | SECURITY INTEREST SEE DOCUMENT FOR DETAILS | 030510 | /0627 | |
Aug 19 2014 | CREDIT SUISSE AG | Alcatel-Lucent USA Inc | RELEASE BY SECURED PARTY SEE DOCUMENT FOR DETAILS | 033949 | /0531 |
Date | Maintenance Fee Events |
May 17 2007 | ASPN: Payor Number Assigned. |
Sep 27 2010 | M1551: Payment of Maintenance Fee, 4th Year, Large Entity. |
Sep 25 2014 | M1552: Payment of Maintenance Fee, 8th Year, Large Entity. |
Sep 20 2018 | M1553: Payment of Maintenance Fee, 12th Year, Large Entity. |
Date | Maintenance Schedule |
Apr 03 2010 | 4 years fee payment window open |
Oct 03 2010 | 6 months grace period start (w surcharge) |
Apr 03 2011 | patent expiry (for year 4) |
Apr 03 2013 | 2 years to revive unintentionally abandoned end. (for year 4) |
Apr 03 2014 | 8 years fee payment window open |
Oct 03 2014 | 6 months grace period start (w surcharge) |
Apr 03 2015 | patent expiry (for year 8) |
Apr 03 2017 | 2 years to revive unintentionally abandoned end. (for year 8) |
Apr 03 2018 | 12 years fee payment window open |
Oct 03 2018 | 6 months grace period start (w surcharge) |
Apr 03 2019 | patent expiry (for year 12) |
Apr 03 2021 | 2 years to revive unintentionally abandoned end. (for year 12) |