CN106610892A - Memory leak detecting method and device - Google Patents

Memory leak detecting method and device Download PDF

Info

Publication number
CN106610892A
CN106610892A CN201510697835.1A CN201510697835A CN106610892A CN 106610892 A CN106610892 A CN 106610892A CN 201510697835 A CN201510697835 A CN 201510697835A CN 106610892 A CN106610892 A CN 106610892A
Authority
CN
China
Prior art keywords
memory
information
function
memory allocation
allocation information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201510697835.1A
Other languages
Chinese (zh)
Other versions
CN106610892B (en
Inventor
毕研涛
周海
陈诚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201510697835.1A priority Critical patent/CN106610892B/en
Publication of CN106610892A publication Critical patent/CN106610892A/en
Application granted granted Critical
Publication of CN106610892B publication Critical patent/CN106610892B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a memory leak detecting method and device. The method comprises the following steps: loading a preset memory monitoring dynamic link library when a detected process is started; hooking a memory allocation function and/or a windows system application programming interface via the memory monitoring dynamic link library; calling the memory allocation function and/or the windows system application programming interface via a hook function, acquiring memory allocation information when the detected process is started, and acquiring memory allocation information when the detected process exits; and comparing the memory allocation information when the detected process is started with the memory allocation information when the detected process exits to obtain memory leak information. By adopting the memory leak detecting method and device, the memory allocation information of the detected process in the whole process from start to exit, so the monitoring time is accurate, the obtained data is comprehensive, the statistical result is not released all the time, and the obtained memory leak information is more accurate.

Description

Memory leakage detecting method and device
Technical field
The present invention relates to internal memory detection field, more particularly to a kind of memory leakage detecting method and device.
Background technology
Memory overflow refers to the leakage of heap memory.Heap memory refers to what program was distributed from heap, and size is arbitrary, Using the internal memory that release must be shown after complete.Application program generally uses the functions such as malloc, realloc, new One piece of internal memory is assigned to from heap, after complete, program must be responsible for calling free or delete to release accordingly The memory block is put, otherwise, this block internal memory cannot be used again, that is, this block memory overflow.
In the special test of conventional client performance, internal memory service condition is the index paid close attention to. UMDH instruments in Windows debugging acid collection (the Debugging Tools for Windows) can be supervised The problem points of memory overflow are controlled, the storehouse at memory overflow is obtained.UMDH monitoring Windows system letters Memory allocation function in number, two time points of beginning and end specified manually by statistical user Memory Allocation situation obtains the memory overflow between the two time points, but specifies be difficult to accurately manually, and The data for obtaining are not comprehensive.
The content of the invention
Based on this, it is necessary to specify time point not accurate enough manually for traditional Memory leakage detection and obtain The incomplete problem of data, there is provided a kind of memory leakage detecting method, the time point of monitoring is accurate and monitors Data it is comprehensive.
Additionally, there is a need to a kind of Memory leakage detection device of offer, the time point of monitoring is accurate and monitoring Data are comprehensive.
A kind of memory leakage detecting method, comprises the following steps:
Default internal memory monitoring dynamic link library is loaded in tested process initiation;
Memory allocation function and/or windows system application journeys are linked up with by the internal memory monitoring dynamic link library Sequence DLL;
The memory allocation function and/or the programming of windows system applications is called to connect by hooking function Mouthful, Memory Allocation information during tested process initiation is collected, and collect the internal memory point when tested process is exited With information;
Memory Allocation information to Memory Allocation information during the tested process initiation and when exiting is compared Draw memory overflow information.
A kind of Memory leakage detection device, including:
Load-on module, for loading default internal memory monitoring dynamic link library in tested process initiation;
Hooking module, for by the internal memory monitoring dynamic link library link up with memory allocation function and/or Windows system application DLLs;
Collection module, for calling the memory allocation function and/or windows systems to answer by hooking function With Program Interfaces, Memory Allocation information during tested process initiation is collected, and collects tested process and moved back Memory Allocation information when going out;
Comparison module, for the internal memory point to Memory Allocation information during the tested process initiation and when exiting It is compared with information and draws memory overflow information.
Above-mentioned memory leakage detecting method and device, by loading internal memory monitoring dynamic in tested process initiation Chained library, by internal memory monitoring dynamic link library memory allocation function is linked up with, during the tested process initiation of collection Memory Allocation information and the Memory Allocation information after exiting, by interior during relatively tested process initiation and when exiting Distribution information is deposited, memory overflow information is drawn, tested process has been monitored and has been started to the whole mistake for exiting from startup Memory Allocation information in journey, the time point of monitoring is accurate, and the data for obtaining are comprehensive, and the knot for coming out Fruit does not discharge all the time, then the memory overflow information for drawing is more accurate.
Description of the drawings
Figure 1A is the internal structure schematic diagram of terminal in one embodiment;
Figure 1B is the internal structure schematic diagram of server in one embodiment;
Fig. 2 is the flow chart of memory leakage detecting method in one embodiment;
Fig. 3 is function calling relationship schematic diagram;
Fig. 4 is that internal memory monitoring information is sent to into data processing process in one embodiment, by the data processing The particular flow sheet that process is processed the internal memory monitoring information;
Fig. 5 A are the schematic diagram of tested process and data processing process transmission data;
Fig. 5 B are the process schematic of transmission data between process;
Fig. 6 is data buffer storage schematic diagram;
Fig. 7 is cache mechanism schematic diagram;
Fig. 8 is memory address comparison schematic diagram in memory image;
Fig. 9 is the schematic diagram compared using function storehouse in memory image;
Figure 10 is the change curve of a storehouse;
Figure 11 is the structured flowchart of memory leak detecting device in one embodiment;
Figure 12 is the structured flowchart of memory leak detecting device in another embodiment;
Figure 13 is the structured flowchart of memory leak detecting device in another embodiment;
Figure 14 is the structured flowchart of memory leak detecting device in another embodiment.
Specific embodiment
In order that the objects, technical solutions and advantages of the present invention become more apparent, below in conjunction with accompanying drawing and reality Example is applied, the present invention will be described in further detail.It should be appreciated that specific embodiment described herein is only Only to explain the present invention, it is not intended to limit the present invention.
It is appreciated that term " first " used in the present invention, " second " etc. can be used to herein describe Various elements, but these elements should not be limited by these terms.These terms be only used for by first element with it is another One element is distinguished.For example, without departing from the scope of the invention, can be by the first client End is referred to as the second client, and similarly, the second client can be referred to as into the first client.First client With the second client both client, but it is not same client.
Figure 1A is the internal structure schematic diagram of terminal in one embodiment.As shown in Figure 1A, the terminal includes logical Cross processor, storage medium, internal memory, network interface, voice collection device, the display of system bus connection Screen, speaker and input equipment.Wherein, the storage medium of terminal is stored with operating system, also including one kind Memory leakage detection device, the Memory leakage detection device is used to realize a kind of memory leakage detecting method.Should Processor is used to provide calculating and control ability, supports the operation of whole terminal.Storage is saved as in terminal The operation of the memory overflow device in medium provides environment, and network interface is used to carry out network service with server, Such as send game data to ask to server, game data that the reception server is returned etc..The display screen of terminal Can be LCDs or electric ink display screen etc., input equipment can be the tactile of covering on display screen Touch button, trace ball or Trackpad, or the external key arranged in layer, or terminal enclosure Disk, Trackpad or mouse etc..The terminal can be mobile phone, panel computer or personal digital assistant.Ability Field technique personnel are appreciated that the structure illustrated in Figure 1A, only related to application scheme part knot The block diagram of structure, does not constitute the restriction of the terminal being applied thereon to application scheme, and specific terminal can To include than more or less of part shown in figure, or some parts are combined, or with different portions Part is arranged.
Figure 1B is the internal structure schematic diagram of server in one embodiment.As shown in Figure 1B, the server Including the processor, storage medium, internal memory, network interface, display screen and the input that are connected by system bus Device.Wherein, the storage medium of the server be stored with operating system, data base and Memory leakage detection dress Put, the scene of game data that are stored with data base, game user data etc., the memory overflow device is used for real Now suitable for a kind of memory leakage detecting method of server.The processor of the server be used for provide calculate and Control ability, supports the operation of whole server.The memory overflow in storage medium is saved as in the server The operation of device provides environment.The display screen of the server can be that LCDs or electric ink show Screen etc., input equipment can be on display screen cover touch layer, or terminal enclosure on arrange by Key, trace ball or Trackpad, or external keyboard, Trackpad or mouse etc..The net of the server Network interface is used to communicate by network connection with outside terminal according to this, such as the game number that receiving terminal sends According to request and to terminal Resume Mission data etc..Server can be with independent server or multiple clothes The server cluster of business device composition is realizing.It will be understood by those skilled in the art that the structure illustrated in Figure 1B, Only the block diagram of the part-structure related to application scheme, does not constitute and application scheme is applied to The restriction of server thereon, specific server can include than more or less of part shown in figure, Or some parts are combined, or arrange with different parts.
Memory overflow refers to that application program is assigned to one piece using functions such as malloc, realloc, new from heap Internal memory, after complete, never call free or delete function is discharged caused by the memory block.Traditional internal memory What leakage detection method compared is the memory overflow situation of two time points that user is specified, and some are applied Program just discharges the internal memory of distribution after exiting, and causes the memory overflow data for detecting not comprehensive, also inaccurate. Memory leakage detecting method in the present invention, by loading internal memory monitoring dynamic link in tested process initiation Storehouse simultaneously performs function therein, starts to monitor Memory Allocation information in tested process initiation, in tested process The internal memory monitoring dynamic link library after loading is still carried out when exiting and monitors the Memory Allocation after tested process is exited Information, Memory Allocation information during by comparing during tested process initiation and exit, draws memory overflow information, Tested process has been monitored from starting the Memory Allocation information that starts to during the entire process of exiting, the time of monitoring Point is accurate, and the data for obtaining comprehensively, and show that memory overflow information is more accurate.
Wherein, malloc functions, i.e. memory allocation, dynamic memory distribution function, if being allocated successfully, Then return and point to the pointer for being allocated internal memory, otherwise return null pointer.
Realloc functions, i.e. reset allocation, Dram Tuning function, if redistributing successfully, Return and point to the pointer for being allocated internal memory, otherwise return null pointer.
New after internal memory has opened up space, returns the first address in this space equivalent to a function.
Free or delete functions, releasing memory.
Memory Allocation information may include the function storehouse of Memory Allocation address, Memory Allocation size and Memory Allocation, Or including Memory Allocation size and the function storehouse of Memory Allocation, or including Memory Allocation address and internal memory Allocated size.
Fig. 2 is the flow chart of memory leakage detecting method in one embodiment.As shown in Fig. 2 a kind of internal memory Leakage detection method, comprises the following steps:
Step 202, default internal memory monitoring dynamic link library is loaded in tested process initiation.
Specifically, initially with the method for static injection, start it is tested enter Cheng Qian use detours tool kits In setdll.exe change process executable file (.exe files), make to be loaded automatically during tested process initiation Default internal memory monitoring dynamic link library (DLL, Dynamic Link Library), so as to hook (hook) Memory allocation function and/or windows systems API (Application Programming Interface, application Program Interfaces).
Step 204, by the internal memory monitoring dynamic link library memory allocation function and/or windows systems are linked up with System application programming interface.
Specifically, hook is realized using the detours storehouses of Microsoft's offer in internal memory monitoring dynamic link library The function of the memory allocation function (malloc, free and realloc etc.) in (hook) C/C++ java standard libraries. Or, hook windows system application DLLs, the i.e. HeapAlloc of hook more bottoms is serial The system function of function (including HeapAlloc, HeapFree and HeapRealloc) or hook bottoms (RtAllocateHeap etc.).HeapAlloc functions are used for the storage allocation on specified heap, and after distributing Internal memory it is irremovable.Using the memory allocation function in hook C/C++ java standard libraries, can remove in a large number The impact of windows system functions, improves the accuracy of result.
Additionally, can also simultaneously hook memory allocation functions and windows system applications DLL it Between switch.
During hook is carried out to two functions of malloc/free, it is possible that can not find the feelings of address Condition, its reason has relation with the on-link mode (OLM) of java standard library, and standard library function both can be from a libc*.lib static state Link, it is also possible to from a msvcrt*.dll dynamic link in program.When program is statically linked to, one Individual program obtains the standard library function of the privately owned version of its own;When dynamic linker, a program is total to Enjoy the static criteria built-in function of version in DLL.Need to make a distinction when malloc/free addresses are obtained.
Fig. 3 is function calling relationship schematic diagram.As shown in figure 3, after new storage allocations, by calling malloc Function, heapalloc functions collect Memory Allocation information.
Step 206, by hooking function the memory allocation function and/or windows system applications are called DLL, collects Memory Allocation information during tested process initiation, and collects when tested process is exited Memory Allocation information.
Specifically, internal memory monitoring dynamic link library mainly monitors malloc operations in internal memory, free operations, bag Include size, the address of Memory Allocation, address, the function storehouse of Memory Allocation of internal memory release of Memory Allocation Deng.Hook function calls memory allocation function malloc or free, by recording malloc operations and free behaviour Make, so as to collect Memory Allocation information during tested process initiation.The Memory Allocation information may include internal memory point Function storehouse with address, Memory Allocation size and Memory Allocation, or including Memory Allocation size and internal memory The function storehouse of distribution, or including Memory Allocation address and Memory Allocation size.
Malloc is used to collect Memory Allocation information.Free functions are used to collect internal memory release information.Internal memory discharges Information may include function storehouse of internal memory release address and/or internal memory release etc..
The statement of malloc series of functions is as follows:
void*__cdecl malloc(_In_size_t_Size);
void__cdecl free(_Inout_opt_void*_Memory);
void*__cdecl realloc(_In_opt_void*_Memory,_In_size_t_NewSize);
As can be seen that the parameter or return of address and size from function call from the statement of malloc series of functions Value can be directly obtained, and storehouse then needs to call the function provided in dbghelp.dll to obtain, and concrete grammar is Calling system function LoadLibrary () loads dbghelp.dll, calls as follows:
HMODULE m_dbgHelp=LoadLibrary (" dbghelp.dll ");
Then concrete function address in DLL is obtained by function GetProcAddress ().
Specifically there are two functions to obtain storehouse, CaptureStackBackTrace () and StackWalk64 (). Both some differences, CaptureStackBackTrace is windows system functions, and calling once can obtain Whole storehouses, speed is fast;StackWalk64 is called and once can only obtain layer stack, and circulation is needed when using Calling could obtain whole storehouses, and speed is slow, and the storehouse that can be obtained is more.
For example, the storehouse that CaptureStackBackTrace (), acquisition is called in funcB is:
funcB()
funcA()
main()
If calling StackWalk64 () in funcB, funcB () can only be obtained, needs are recalled and once obtained FuncA (), recursive call, until can not again obtain storehouse.
In individual embodiment, above-mentioned memory leakage detecting method also includes:Function is obtained using storehouse is global (such as CaptureStackBackTrace) storehouse is obtained, if obtaining failure, then function is obtained using storehouse local (such as StackWalk64) is obtained once.
Step 208, the Memory Allocation information to Memory Allocation information during the tested process initiation and when exiting is entered Go to compare and draw memory overflow information.
Specifically, the Memory Allocation information may include Memory Allocation address, Memory Allocation size and Memory Allocation Function storehouse, or including Memory Allocation size and the function storehouse of Memory Allocation, or including internal memory point With address and Memory Allocation size.
In one embodiment, can by the Memory Allocation address in Memory Allocation information during tested process initiation and The Memory Allocation address in Memory Allocation information when exiting is compared, internal memory when judging that tested process is exited The memory address more than in Memory Allocation information during tested process initiation in distribution information, then many memory address For memory overflow address, then draw memory overflow size.
In another embodiment, by the function storehouse of Memory Allocation information during tested process initiation and can exit When Memory Allocation information in function storehouse be compared, Memory Allocation information when judging that tested process is exited The middle function storehouse more than in Memory Allocation information during tested process initiation, function storehouse more is function storehouse Memory overflow.
In one embodiment, many function storehouses are ranked up according to corresponding function address size, then Classified statistic is carried out to the function storehouse after sequence, show that function stack memory leakage number of times and function internal memory are let out Leakage size.
Specifically, many function storehouses are classified, are counted the leakage number of times of of a sort function storehouse, And calculate all function stack memory leak sizes.
The comparison of really one group of number is compared using function storehouse, all equal just calculation phase of interior each number is only organized With function storehouse, judging whether two function storehouses equal needs all to compare per number, and a large amount of storehouses are searched When than relatively time-consuming, using giving function heap sort, can by function storehouse according to function address from big to small Sequence, or sort from small to large.Function storehouse after sequence process is by using std::Set data structure realities Existing RBTree management, makes lookup time complexity be reduced to O (lgn), highly shortened the lookup time.
Additionally, can also count the code line of memory overflow, the order of severity, the function storehouse of Memory Allocation Variation tendency etc., by the more preferable memory leak positioning problem of the variation tendency of function storehouse.
Above-mentioned memory leakage detecting method, by loading internal memory monitoring dynamic link library in tested process initiation, Memory allocation function is linked up with by internal memory monitoring dynamic link library, Memory Allocation during tested process initiation is collected Information and the Memory Allocation information after exiting, by Memory Allocation letter during relatively tested process initiation and when exiting Breath, draw memory overflow information, monitored tested process from start start to during the entire process of exiting in Distribution information is deposited, the time point of monitoring is accurate, and the data for obtaining are comprehensive, and the result for coming out is all the time Without release, then the memory overflow information for drawing is more accurate.
In one embodiment, above-mentioned memory leakage detecting method also includes:Call this interior by hooking function Partition function and/or windows system application DLLs are deposited, the internal memory after tested process initiation is collected Monitoring information;The internal memory monitoring information is sent to into data processing process, it is interior to this by the data processing process Deposit monitoring information to be processed.
Specifically, internal memory monitoring information can be Memory Allocation information or internal memory release information.Memory Allocation information The function storehouse of Memory Allocation address, Memory Allocation size and Memory Allocation is may include, or including internal memory point Function storehouse with size and Memory Allocation, or including Memory Allocation address and Memory Allocation size.Internal memory Release information may include function storehouse of internal memory release address and/or internal memory release etc..
Data processing process is processed internal memory monitoring information, and the internal memory monitoring information collected is mainly two Kind, one kind is storage allocation, and one is releasing memory.During storage allocation, Memory Allocation information is recorded, released When putting internal memory, the Memory Allocation information of deletion record, it is exactly that current distribution is not released so to count the data for obtaining The internal memory put.
Data processing process is processed internal memory monitoring information, and the data structure of record can adopt std::Map, Because map is that RBTree is realized, it is adapted to do and frequently searches, inserts and deletion action, these three operations Time complexity is all O (lgn).Specific data structure statement is as follows:
Wherein, the key assignments (key) of map is the address of storage allocation.
By the Memory Allocation information for comparing two measuring points, analyze and newly distribute between the two time points Out and without the internal memory of release, memory overflow is wherein.Test in the present embodiment time point used be by When surveying process initiation and after tested process exits, the result for so coming out does not discharge all the time, can It is exactly memory overflow to assert, accuracy rate is very high.
Factor data collect and process all write in internal memory dynamic link library, but due to data processing take it is more, Process may be caused to become serious interim card, processed the data is activation collected to another process and exported knot Really, the burden of tested process can be mitigated, it is to avoid interim card occur, and data-handling efficiency can be improved.
Fig. 4 is that internal memory monitoring information is sent to into data processing process in one embodiment, by the data processing The particular flow sheet that process is processed the internal memory monitoring information.As shown in figure 4, by internal memory monitoring information Data processing process is sent to, is wrapped the step of processed the internal memory monitoring information by the data processing process Include:
Step 402, by the internal memory monitoring information write shared drive.
Step 404, the internal memory monitoring letter in the shared drive is read by the monitoring thread of the data processing process Breath, and be stored in the caching of the data processing process.
Step 406, by the distribution thread of the data processing process internal memory monitoring information is taken out from the caching, And distribute to the process thread of the data processing process and processed.
Specifically, processing thread can adopt multiple, such as 5,8.For the centre below four cores Reason device can accordingly reduce process Thread Count.In the present embodiment, using 5 process threads, using multiple places Reason thread can improve treatment effeciency.
Step 408, refreshing at internal memory monitoring information of the thread to the tested process by the data processing process The Memory Allocation information that reason is obtained is refreshed.
Module name that the function name and function that refreshing thread is mainly used in analytical function storehouse is located etc..
The internal memory monitoring information of collection is sent to data processing process by tested process, is related to interprocess communication, The transmission of data can be realized by the way of shared drive, it is fast, not error-prone using shared drive transmission speed.
Fig. 5 A are the schematic diagram of tested process and data processing process transmission data.As shown in Figure 5A, it is tested Internal memory monitoring dynamic link library is injected in process, malloc/free functions is called, is collected related data, storage The data of storage are transferred to data processing process by the data of collection, and data processing process carries out data storage And process, leakage filter with analysis, memory overflow result output, filter arrange, monitoring kernel arrange etc..
Fig. 5 B are the process schematic of transmission data between process.As shown in Figure 5 B, in tested process is collected Deposit distribution and discharge operation, internal memory monitoring dynamic link library will be written to the data of collection in shared drive, Monitoring thread in data processing process (such as TMemAnalyzer.exe), finds there are data in shared drive Will read out.
Fig. 6 is data buffer storage schematic diagram.As shown in fig. 6, increasing caching in data processing process, it is used for Temporarily deposit the data (number that i.e. monitoring thread reads out from shared drive that tested process is sended over According to), original data are received into a synchronous mode for processing and is changed to what data collection and data processing separated Asynchronous mode, collection of the data processing on data does not result in too big impact, then tested process collects data Data processing process can be just sent to, tested process transmission data can be avoided slow and interim card.The data of caching Structure is the queue of a first in first out, it is ensured that the order of data processing is correct.
Due to malloc and free data processing stage be two reciprocal processes (malloc inserts data, Free deletes data), if it is (right that corresponding malloc and free data can be found before data processing stage Same memory address should be referred to), the two reciprocal operations just can be saved, improve efficiency, be this in the buffer Add a cache (cache).Search from cache when a free data enter caching Corresponding malloc data, if finding corresponding malloc data, delete free data and corresponding Malloc data.The big I of cache sets as needed, such as can for 64 size of data, 128 Size of data, 256 size of data etc..Using the cache of 128 size of data, easily mistake can be avoided Big lookup every time takes, and the problem that the too small hit rate of capacity declines.
In one embodiment, above-mentioned memory overflow method also includes:When the internal memory monitoring information is released for internal memory When putting information, search whether exist from the cache of the data processing process according to the internal memory release information Corresponding Memory Allocation information, if so, then deletes the internal memory release information and corresponding Memory Allocation information, If it is not, then searching whether there is corresponding Memory Allocation information from caching, delete the internal memory if existing and release Put information and corresponding Memory Allocation information.
Fig. 7 is cache mechanism schematic diagram.As shown in fig. 7, the data syn-chronization write that tested process is collected In shared drive, then data processing process reads data from shared drive and keeps in in caching, reads Data be that internal memory discharges information, then search whether to exist in the cache from own cache in corresponding Distribution information is deposited, if existing, the internal memory release information and corresponding Memory Allocation information is deleted, if not depositing , then search whether there is corresponding Memory Allocation information from caching, the internal memory release is deleted if existing Information and corresponding Memory Allocation information.
In order to obtain Memory Allocation information sometime, memory image can be used.Memory image is at certain Moment malloc is assigned with and never calls the set of internal memory that free discharged.Entirely applying journey In the life cycle of sort run, the memory image at each moment can be varied from substantially, because with application Program is constantly constantly operated by user, and internal memory is occurring to change always.Get the interior of each moment Deposit snapshot, it is known that there occurs between two memory images the memory image of which internal memory operation, i.e., two it Between there occurs memory overflow, the memory address of memory overflow is obtained by the comparison of two memory images.
Fig. 8 is memory address comparison schematic diagram in memory image.As shown in figure 8, in function at first Collection snapshot 1, gathers snapshot 2 when function terminates, find that the 0x2 of snapshot 1 is carried out through this process Release operation, so not existing in snapshot 2,0x1 is still present in the snapshot 2, then illustrate 0x1 is not released, and 0x3 and 0x4 is just had in snapshot 2, then illustrate that 0x3 and 0x4 memory blocks are Distribute in the function, and also without release in time after function terminates, then the two memory blocks are to let out Leakage memory block.
Fig. 9 is the schematic diagram compared using function storehouse in memory image.As shown in figure 9, starting in function When gather snapshot 1, snapshot 2 is gathered when function terminates, find through this process, entered function Afterwards, release the memory block that preamble scene is not used, will snapshot 1 0x2 carried out release operation, 0x1 Still exist in snapshot 2, then illustrate that 0x1 is not released, 0x3 and 0x4 is to leave returned again after function To preamble scene interface, program is assigned with associated internal memory block again, is have this two block address memory in snapshot 1 Corresponding function storehouse.0x5 is that just have in snapshot 2, the associated internal memory block distributed again after entered function, And function terminate after also without in time release, then memory block 0x5 is the storehouse of leakage.
The process of the memory leakage detecting method of the present invention is illustrated with reference to specific application scenarios.To play In program, player enters another scene from a scene, and after another scene terminates original field is returned to Scape, its Memory leakage detection includes:
(a1) starting to collect the first memory image to preamble scene into primary measured scene backed off after random, should First memory image records the Memory Allocation information at current time;
(a2) be re-introduced into tested scene backed off after random to preamble scene start collect the second memory image, Second memory image records the Memory Allocation information at current time;
(a3) internal memory point of the Memory Allocation information for recording the first memory image and the second memory image record It is compared with information, draws the memory overflow information of tested scene.
Using a1 to a3 steps, time point can be arranged by player, meet the individual demand of player.
Or, its Memory leakage detection includes:
(b1) the first memory image is collected when games start, the first memory image record is worked as The Memory Allocation information at front moment;
(b2) the second memory image is collected when games are exited, when second memory image records current The Memory Allocation information at quarter;
(b3) internal memory point of the Memory Allocation information for recording the first memory image and the second memory image record It is compared with information, draws the memory overflow information of tested scene.
Using b1 to b3 steps, use games from start to exit after two snapshots collecting, The leakage that relatively the two snapshots draw is more accurate.
Memory Allocation information includes Memory Allocation address, Memory Allocation size and memory allocation function storehouse.
The Memory Allocation information of the Memory Allocation information that the first memory image is recorded and the second memory image record The step of being compared includes:By the function storehouse in the Memory Allocation information of first memory image record and Function storehouse in the Memory Allocation information of the second memory image record is compared, and judges that second internal memory is fast According to function heap many in the Memory Allocation information in the Memory Allocation information of record than the first memory image record Stack, then many function storehouses are the leakage of function stack memory.
Further, many function storehouses are ranked up according to corresponding function address size, then to sequence Function storehouse afterwards carries out classified statistic, draws function stack memory leakage number of times and function memory overflow size.
Specifically, function storehouse is classified, is counted the leakage number of times of of a sort function storehouse, and counted Calculate all function stack memory leak sizes.
The comparison of really one group of number is compared using function storehouse, all equal just calculation phase of interior each number is only organized With function storehouse, judging whether two function storehouses equal needs all to compare per number, and a large amount of storehouses are searched When than relatively time-consuming, using giving function heap sort, can by function storehouse according to function address from big to small Sequence, or sort from small to large.Function storehouse after sequence process is by using std::Set data structure realities Existing RBTree management, makes lookup time complexity be reduced to O (lgn), highly shortened the lookup time.
Come out memory overflow information is detailed by above-mentioned memory leakage detecting method, including leakage Volume function storehouse (can in detail arrive code line), size, number of times.Because of malloc/free except programmer makes in itself With outer, the function of C run-time librarys also can be used in a large number, such as fopen_s is presented herein below its allocating stack.
.exe!Malloc (unsigned int size=24) Line87
.exe!_ malloc_crt (unsigned int cb=24) Line44
.exe!_ mtinitlocknum (int locknum=19) Line274
.exe!_getstream()Line71
.exe!_ fsopen (const char * file=0x00546244, const char* mode=0x00546240, int Shflag=128) Line61
.exe!Fopen_s (_ iobuf**pfile=0x001df994, const char*file=0x00546244, const Char*mode=0x00546240) Line160
.exe!Main (int argc=1, char**argv=0x00662b98) Line32
For this purpose, RAM leakage information is filtered by keyword.Keyword can be key set in advance Word.The RAM leakage information for filtering out matching by keyword is shown.
Above-mentioned method for detecting memory leakage also includes:By the leakage order of severity of storehouse according to carrying out from big to small Sequence, the storehouse for revealing the preceding predetermined quantity of order of severity sequence is shown.
Reveal the order of severity and refer to that leak degree is more than default percentage ratio.It is big that such as same storehouse reveals size In the first preset value;Same storehouse reveals number of times and is more than the second preset value;Same storehouse is revealed according to time shafts Size is in rising trend, ascendant trend more than the 3rd preset value, such as 30%;Distribute identical big in same storehouse Little memory block accounts for the accounting degree of total allocation block and is more than the 4th preset value, and such as 50%.
In one embodiment, above-mentioned method for detecting memory leakage also includes:By the change curve of each storehouse Figure shows, and allows developer more accurately to judge leakage process.Figure 10 is that the change of a storehouse is bent Line chart.As shown in Figure 10, the number of times revealed every the storehouse of predetermined interval, abscissa is the time, single Position is the second, and vertical coordinate is leakage number of times.
In one embodiment, above-mentioned method for detecting memory leakage also includes:User Interface is provided, and Trigger control is set on User Interface.By the trigger control on User Interface, can complete interior Deposit leak detection, it is not necessary to the different order of user input, it is simple to operate.
Above-mentioned method for detecting memory leakage can be applicable to any application, not have to the performance of any application program Have an impact, by the way of system api layer and java standard library layer flexible configuration hook is carried out, add filtering policy And the order of severity definition, improve the accuracy and readability of testing result, can take into account games and other Application program, is not required to code, can disposably detect, and to single scene analysis.
Above-mentioned method for detecting memory leakage is applied to《Cavalry》, in client performance test process scene is found (64 robot doctors place incense burner 15 minutes repeatedly in the city of Jiangling, after the completion of automatically exit from) exists bright Aobvious RAM leakage.Analysis result:Two snapshots are respectively intercepted entering and exiting before and after the city of Jiangling, by right Than, reveal 335.8M (million) altogether in the test process of whole 15 minutes, cross 3 minutes or so internal memories and released 290.5M is put, until exit internal memory before the scene do not change, that is, has been exited before scene and is caused 45.3M RAM leakage.In testing, there are 216 relational stacks, call altogether 7023 times, reveal 47536935 Byte.
Above-mentioned method for detecting memory leakage is applied to《MHP》, RAM leakage is most obvious in test process Can find out there is RAM leakage by memory manager.Analysis result:By analyze it is this kind of reveal from The leakage of the flash file in program, the leakage of current scaleform is all belonging to this kind of, and its invoked procedure is: Main swf files are called in flashplayer instance.cpp in engine, in swf files scaleform is called. Therefore there is RAM leakage in the swf related to UI, storehouse all can be called in scaleform.
Figure 11 is the structured flowchart of memory leak detecting device in one embodiment.As shown in figure 11, it is a kind of Memory leakage detection device, corresponding to the functional module framework constructed by method for detecting memory leakage, description is not In detail part reference method description, including load-on module 1102, Hooking module 1104, collection module 1106, Comparison module 1108.Wherein:
Load-on module 1102 is used to load default internal memory monitoring dynamic link library in tested process initiation.
Specifically, initially with the method for static injection, start it is tested enter Cheng Qian use detours tool kits In setdll.exe change process executable file (.exe files), make to be loaded automatically during tested process initiation Default internal memory monitoring dynamic link library (DLL, Dynamic Link Library), so as to hook (hook) Memory allocation function and/or windows systems API (Application Programming Interface, application Program Interfaces).
Hooking module 1104 be used for by the internal memory monitoring dynamic link library link up with memory allocation function or Windows system application DLLs.
Specifically, hook is realized using the detours storehouses of Microsoft's offer in internal memory monitoring dynamic link library The function of the memory allocation function (malloc, free and realloc etc.) in (hook) C/C++ java standard libraries. Or, hook windows system application DLLs, the i.e. HeapAlloc of hook more bottoms is serial The system function of function (including HeapAlloc, HeapFree and HeapRealloc) or hook bottoms (RtAllocateHeap etc.).HeapAlloc functions are used for the storage allocation on specified heap, and after distributing Internal memory it is irremovable.Using the memory allocation function in hook C/C++ java standard libraries, can remove in a large number The impact of windows system functions, improves the accuracy of result.
Additionally, can also simultaneously hook memory allocation functions and windows system applications DLL it Between switch.
Collection module 1106 is used to call the memory allocation function or windows system applications by hooking function Program Interfaces, collect Memory Allocation information during tested process initiation, and collect tested process and exit When Memory Allocation information.
Specifically, internal memory monitoring dynamic link library mainly monitors malloc operations in internal memory, free operations, bag Include size, the address of Memory Allocation, address, the function storehouse of Memory Allocation of internal memory release of Memory Allocation Deng.Hook function calls memory allocation function malloc or free, by recording malloc operations and free behaviour Make, so as to collect Memory Allocation information during tested process initiation.The Memory Allocation information may include internal memory point Function storehouse with address, Memory Allocation size and Memory Allocation, or including Memory Allocation size and internal memory The function storehouse of distribution, or including Memory Allocation address and Memory Allocation size.
Internal memory point when comparison module 1108 is used for Memory Allocation information during the tested process initiation and exits It is compared with information and draws memory overflow information.
Specifically, the Memory Allocation information may include Memory Allocation address, Memory Allocation size and Memory Allocation Function storehouse, or including Memory Allocation size and the function storehouse of Memory Allocation, or including internal memory point With address and Memory Allocation size.
In one embodiment, comparison module 1108 can be by Memory Allocation information during tested process initiation The Memory Allocation address deposited in distribution address and Memory Allocation information when exiting is compared, judge it is tested enter Memory address more than in Memory Allocation information during tested process initiation in Memory Allocation information when journey is exited, then Many memory address are memory overflow address, then draw memory overflow size.
In another embodiment, comparison module 1108 can be by the letter of Memory Allocation information during tested process initiation Number storehouse is compared with the function storehouse in Memory Allocation information when exiting, when judging that tested process is exited The function storehouse more than in Memory Allocation information during tested process initiation in Memory Allocation information, function heap more Stack is the leakage of function stack memory.
Figure 12 is the structured flowchart of memory leak detecting device in another embodiment.As shown in figure 12, one Kind of Memory leakage detection device, except including load-on module 1102, Hooking module 1104, collection module 1106, Comparison module 1108, also including the first statistical module 1110.Wherein:
First statistical module 1110 is used to arrange many function storehouses according to corresponding function address size Sequence, then classified statistic is carried out to the function storehouse after sequence, draw function stack memory leakage number of times and function Memory overflow size.
Specifically, function storehouse is classified, is counted the leakage number of times of of a sort function storehouse, and counted Calculate all function stack memory leak sizes.
The comparison of really one group of number is compared using function storehouse, all equal just calculation phase of interior each number is only organized With function storehouse, judging whether two function storehouses equal needs all to compare per number, and a large amount of storehouses are searched When than relatively time-consuming, using giving function heap sort, can by function storehouse according to function address from big to small Sequence, or sort from small to large.Function storehouse after sequence process is by using std::Set data structure realities Existing RBTree management, makes lookup time complexity be reduced to O (lgn), highly shortened the lookup time.
Additionally, can also count the code line of memory overflow, the order of severity, the function storehouse of Memory Allocation Variation tendency etc., by the more preferable memory leak positioning problem of the variation tendency of function storehouse.
Above-mentioned Memory leakage detection device, by loading internal memory monitoring dynamic link library in tested process initiation, Memory allocation function is linked up with by internal memory monitoring dynamic link library, Memory Allocation during tested process initiation is collected Information and the Memory Allocation information after exiting, by Memory Allocation letter during relatively tested process initiation and when exiting Breath, draw memory overflow information, monitored tested process from start start to during the entire process of exiting in Distribution information is deposited, the time point of monitoring is accurate, and the data for obtaining are comprehensive, and the result for coming out is all the time Without release, then the memory overflow information for drawing is more accurate.
In one embodiment, collection module 1106 is additionally operable to call the memory allocation function by hooking function And/or windows system application DLLs, collect the internal memory monitoring information after tested process initiation.
Figure 13 is the structured flowchart of memory leak detecting device in another embodiment.As shown in figure 13, one Kind of Memory leakage detection device, except including load-on module 1102, Hooking module 1104, collection module 1106, Comparison module 1108, also including transport module 1112, read module 1114, memory module 1116, taking-up mould Block 1118, distribute module 1120, refresh module 1122, searching modul 1124, removing module 1126.
Wherein:Transport module 1112 is used to for the internal memory monitoring information to be sent to data processing process, by the number The internal memory monitoring information is processed according to treatment progress.
Transport module 1112 is additionally operable in the internal memory monitoring information write shared drive.
Read module 1114 is interior in the shared drive for being read by the monitoring thread of the data processing process Deposit monitoring information.
Memory module 1116 is used to that the internal memory monitoring information of reading to be stored in the caching of the data processing process.
Taking out module 1118 is used to that internal memory prison to be taken out from the caching by the distribution thread of the data processing process Control information.
Distribute module 1120 is used to distribute to the process thread of the data processing process and is processed.
Refresh module 1122 is used to supervise the internal memory of the tested process by the thread that refreshes of the data processing process The Memory Allocation information that control information processing is obtained is refreshed.
The internal memory monitoring information is Memory Allocation information or internal memory release information;
Searching modul 1124 is used for when the internal memory monitoring information is that internal memory discharges information, according to the internal memory release Information searches whether there is corresponding Memory Allocation information from the cache of the data processing process.
If removing module 1126 is used for the presence of corresponding Memory Allocation letter in the cache of the data processing process Breath, then delete the internal memory release information and corresponding Memory Allocation information.
So that in games, player enters another scene from a scene, the weight after another scene terminates The scene reverted, its Memory leakage detection includes:
Collection module 1106 is additionally operable to starting collection first to preamble scene into primary measured scene backed off after random Memory image, first memory image records the Memory Allocation information at current time, and is being re-introduced into Tested scene backed off after random starts to collect the second memory image to preamble scene, and the second memory image record is current The Memory Allocation information at moment;
Comparison module 1108 is additionally operable to Memory Allocation information and the second memory image for recording the first memory image The Memory Allocation information of record is compared, and draws the memory overflow information of tested scene.
Or, collection module 1106 is additionally operable to collect the first memory image when games start, and this first Memory image records the Memory Allocation information at current time, and the second internal memory is collected when games are exited Snapshot, second memory image records the Memory Allocation information at current time;
Comparison module 1108 is additionally operable to Memory Allocation information and the second memory image for recording the first memory image The Memory Allocation information of record is compared, and draws the memory overflow information of tested scene.
The Memory Allocation information includes the size that the address that do not discharge of Memory Allocation, Memory Allocation do not discharge and interior Deposit the function storehouse that distribution does not discharge;
Comparison module 1108 is additionally operable to the function storehouse in the Memory Allocation information of the first memory image record It is compared with the function storehouse in the Memory Allocation information of the second memory image record, judges that the second internal memory is fast According to function heap many in the Memory Allocation information in the Memory Allocation information of record than the first memory image record Stack, then many function storehouses are the leakage of function stack memory.
Figure 14 is the structured flowchart of memory leak detecting device in another embodiment.As shown in figure 14, one Kind of Memory leakage detection device, except including load-on module 1102, Hooking module 1104, collection module 1106, Comparison module 1108, also including the second statistical module 1128.
Second statistical module 1128 is used to arrange many function storehouses according to corresponding function address size Sequence, then classified statistic is carried out to the function storehouse after sequence, draw function stack memory leakage number of times and function Memory overflow size.
Specifically, function storehouse is classified, is counted the leakage number of times of of a sort function storehouse, and counted Calculate all function stack memory leak sizes.
In other embodiments, RAM leakage device may include load-on module 1102, Hooking module 1104, receive Collection module 1106, comparison module 1108, the first statistical module 1110, transport module 1112, read module 1114th, memory module 1116, taking-up module 1118, distribute module 1120, refresh module 1122, lookup mould Block 1124, removing module 1126, any possible combination of the second statistical module 1128.
One of ordinary skill in the art will appreciate that all or part of flow process in above-described embodiment method is realized, Computer program be can be by instruct the hardware of correlation to complete, it is non-easy that described program can be stored in one In the property lost computer read/write memory medium, the program is upon execution, it may include such as the enforcement of above-mentioned each method The flow process of example.Wherein, described storage medium can be magnetic disc, CD, read-only memory (Read-Only Memory, ROM) etc..
Embodiment described above only expresses the several embodiments of the present invention, and its description is more concrete and detailed, But therefore can not be interpreted as the restriction to the scope of the claims of the present invention.It should be pointed out that for this area Those of ordinary skill for, without departing from the inventive concept of the premise, can also make it is some deformation and Improve, these belong to protection scope of the present invention.Therefore, the protection domain of patent of the present invention should be with appended Claim is defined.

Claims (18)

1. a kind of memory leakage detecting method, comprises the following steps:
Default internal memory monitoring dynamic link library is loaded in tested process initiation;
Memory allocation function and/or windows system application journeys are linked up with by the internal memory monitoring dynamic link library Sequence DLL;
The memory allocation function and/or the programming of windows system applications is called to connect by hooking function Mouthful, Memory Allocation information during tested process initiation is collected, and collect the internal memory point when tested process is exited With information;
Memory Allocation information to Memory Allocation information during the tested process initiation and when exiting is compared Draw memory overflow information.
2. method according to claim 1, it is characterised in that methods described also includes:
The memory allocation function and/or the programming of windows system applications is called to connect by hooking function Mouthful, collect the internal memory monitoring information after tested process initiation;
The internal memory monitoring information is sent to into data processing process, by the data processing process to described interior Deposit monitoring information to be processed.
3. method according to claim 2, it is characterised in that described to send out the internal memory monitoring information Data processing process is given, process step bag is carried out to the internal memory monitoring information by the data processing process Include:
The internal memory monitoring information is write in shared drive;
The internal memory monitoring information in the shared drive is read by the monitoring thread of the data processing process, And be stored in the caching of the data processing process;
Internal memory monitoring information is taken out from the caching by the distribution thread of the data processing process, and is divided The process thread of data processing process described in dispensing is processed;
Obtained by the internal memory monitoring information processing of the thread to the tested process that refresh of the data processing process To Memory Allocation information refreshed.
4. method according to claim 3, it is characterised in that the internal memory monitoring information is internal memory point With information or internal memory release information;
Methods described also includes:
When the internal memory monitoring information is that internal memory discharges information, information is discharged from the number according to the internal memory According to searching whether there is corresponding Memory Allocation information in the cache for the treatment of progress, institute is if so, then deleted State internal memory release information and corresponding Memory Allocation information.
5. method according to claim 1, it is characterised in that the Memory Allocation information includes internal memory The function storehouse of distribution address, Memory Allocation size and Memory Allocation;
The Memory Allocation information to during the tested process initiation and Memory Allocation information when exiting are carried out The step of relatively drawing memory overflow information includes:
By the function storehouse in Memory Allocation information during the tested process initiation and Memory Allocation when exiting Function storehouse in information is compared, than tested in Memory Allocation information when judgement show that tested process is exited Many function storehouses in Memory Allocation information during process initiation, then many function storehouses are function storehouse Memory overflow.
6. method according to claim 5, it is characterised in that methods described also includes:
Many function storehouses are ranked up according to corresponding function address size, then to the function heap after sequence Stack carries out classified statistic, draws function stack memory leakage number of times and function memory overflow size.
7. method according to claim 1, it is characterised in that methods described also includes:
Into primary measured scene backed off after random to preamble scene start collect the first memory image, described first Memory image records the Memory Allocation information at current time;
Start to collect the second memory image to preamble scene tested scene backed off after random is re-introduced into, described the Two memory images record the Memory Allocation information at current time;
The Memory Allocation information of the Memory Allocation information that the first memory image is recorded and the second memory image record It is compared, draws the memory overflow information of tested scene;
Or, the first memory image is collected when games start, the first memory image record is current The Memory Allocation information at moment;
The second memory image is collected when games are exited, the second memory image record current time Memory Allocation information;
The Memory Allocation information of the Memory Allocation information that the first memory image is recorded and the second memory image record It is compared, draws the memory overflow information of tested scene.
8. method according to claim 7, it is characterised in that the Memory Allocation information includes internal memory The function storehouse of distribution address, Memory Allocation size and Memory Allocation;
The Memory Allocation information of the Memory Allocation information that the first memory image is recorded and the second memory image record The step of being compared includes:
Function storehouse and the second memory image note in the Memory Allocation information that first memory image is recorded Function storehouse in the Memory Allocation information of record is compared, and judgement draws the internal memory that the second memory image is recorded It is than many function storehouse in the Memory Allocation information of the first memory image record in distribution information, then described many Function storehouse is the leakage of function stack memory.
9. method according to claim 8, it is characterised in that methods described also includes:
Many function storehouses are ranked up according to corresponding function address size, then to the function heap after sequence Stack carries out classified statistic, draws function stack memory leakage number of times and function memory overflow size.
10. a kind of Memory leakage detection device, it is characterised in that include:
Load-on module, for loading default internal memory monitoring dynamic link library in tested process initiation;
Hooking module, for by the internal memory monitoring dynamic link library link up with memory allocation function and/or Windows system application DLLs;
Collection module, for calling the memory allocation function and/or windows systems to answer by hooking function With Program Interfaces, Memory Allocation information during tested process initiation is collected, and collects tested process and moved back Memory Allocation information when going out;
Comparison module, for the internal memory point to Memory Allocation information during the tested process initiation and when exiting It is compared with information and draws memory overflow information.
11. devices according to claim 10, it is characterised in that the collection module is additionally operable to pass through Hooking function calls the memory allocation function and/or windows system application DLLs, collects quilt The internal memory monitoring information surveyed after process initiation;
Described device also includes:
Transport module, for the internal memory monitoring information to be sent to into data processing process, by the data Reason process is processed the internal memory monitoring information.
12. devices according to claim 11, it is characterised in that the transport module is additionally operable to institute In stating internal memory monitoring information write shared drive;
Described device also includes:
Read module, for being read in the shared drive by the monitoring thread of the data processing process Internal memory monitoring information;
Memory module, for the internal memory monitoring information of reading to be stored in the caching of the data processing process;
Module is taken out, for taking out internal memory from the caching by the distribution thread of the data processing process Monitoring information;
Distribute module, the process thread for distributing to the data processing process is processed;
Refresh module, for refreshing internal memory of the thread to the tested process by the data processing process The Memory Allocation information that monitoring information process is obtained is refreshed.
13. devices according to claim 12, it is characterised in that the internal memory monitoring information is internal memory Distribution information or internal memory release information;
Described device also includes:
Searching modul, for when the internal memory monitoring information is that internal memory discharges information, being released according to the internal memory Put information and search whether there is corresponding Memory Allocation information from the cache of the data processing process;
Removing module, if there is corresponding Memory Allocation letter in the cache for the data processing process Breath, then delete the internal memory release information and corresponding Memory Allocation information.
14. devices according to claim 10, it is characterised in that the Memory Allocation information includes interior Deposit the function storehouse of distribution address, Memory Allocation size and Memory Allocation;
The comparison module is additionally operable to the function storehouse in Memory Allocation information during the tested process initiation It is compared with the function storehouse in Memory Allocation information when exiting, judgement show that tested process is interior when exiting Deposit function storehouses more than in Memory Allocation information during tested process initiation in distribution information, then it is described many Function storehouse is the leakage of function stack memory.
15. devices according to claim 14, it is characterised in that described device also includes:
First statistical module, for being ranked up according to corresponding function address size to many function storehouses, Again classified statistic is carried out to the function storehouse after sequence, draw function stack memory leakage number of times and function internal memory Leak sizes.
16. devices according to claim 10, it is characterised in that the collection module is additionally operable to entering Enter primary measured scene backed off after random to start to collect the first memory image, first memory image to preamble scene The Memory Allocation information at record current time, and tested scene backed off after random is being re-introduced into preamble scene Start to collect the second memory image, second memory image records the Memory Allocation information at current time;
The comparison module is additionally operable to Memory Allocation information and the second memory image for recording the first memory image The Memory Allocation information of record is compared, and draws the memory overflow information of tested scene;
Or, the collection module is additionally operable to collect the first memory image when games start, and described One memory image records the Memory Allocation information at current time, and collects in second when games are exited Snapshot is deposited, second memory image records the Memory Allocation information at current time;
The comparison module is additionally operable to Memory Allocation information and the second memory image for recording the first memory image The Memory Allocation information of record is compared, and draws the memory overflow information of tested scene.
17. devices according to claim 16, it is characterised in that the Memory Allocation information includes interior Deposit the function storehouse of distribution address, Memory Allocation size and Memory Allocation;
The comparison module is additionally operable to the function heap in the Memory Allocation information for recording first memory image Function storehouse in the Memory Allocation information of stack and the second memory image record is compared, and judgement draws second Many letters in Memory Allocation information in the Memory Allocation information of memory image record than the first memory image record Number storehouse, then many function storehouses are that function stack memory is leaked.
18. devices according to claim 17, it is characterised in that described device also includes:
Second statistical module, for being ranked up according to corresponding function address size to many function storehouses, Again classified statistic is carried out to the function storehouse after sequence, draw function stack memory leakage number of times and function internal memory Leak sizes.
CN201510697835.1A 2015-10-23 2015-10-23 Memory leak detection method and device Active CN106610892B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510697835.1A CN106610892B (en) 2015-10-23 2015-10-23 Memory leak detection method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510697835.1A CN106610892B (en) 2015-10-23 2015-10-23 Memory leak detection method and device

Publications (2)

Publication Number Publication Date
CN106610892A true CN106610892A (en) 2017-05-03
CN106610892B CN106610892B (en) 2020-12-22

Family

ID=58612791

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510697835.1A Active CN106610892B (en) 2015-10-23 2015-10-23 Memory leak detection method and device

Country Status (1)

Country Link
CN (1) CN106610892B (en)

Cited By (25)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107145447A (en) * 2017-05-09 2017-09-08 网易(杭州)网络有限公司 Detect method, device and the electronic equipment of memory overflow
CN107360317A (en) * 2017-06-29 2017-11-17 努比亚技术有限公司 The detection method and mobile terminal, storage medium of application resource leakage
CN107480047A (en) * 2017-07-13 2017-12-15 珠海金山网络游戏科技有限公司 A kind of method and device of internal memory auto snapshot
CN107562586A (en) * 2017-08-16 2018-01-09 努比亚技术有限公司 A kind of internal-memory detection method, equipment and computer-readable storage medium
CN107797898A (en) * 2017-09-28 2018-03-13 东软集团股份有限公司 Collecting method and its device
CN107908539A (en) * 2017-07-24 2018-04-13 平安科技(深圳)有限公司 A kind of method, terminal and computer-readable recording medium for detecting application program RAM leakage
CN108108258A (en) * 2017-12-29 2018-06-01 杭州迪普科技股份有限公司 The restorative procedure and device of a kind of RAM leakage
CN108121602A (en) * 2017-12-14 2018-06-05 捷开通讯(深圳)有限公司 A kind of method, electronic equipment and the storage medium of definite garbage collection trigger point
CN108334435A (en) * 2018-01-18 2018-07-27 杭州迪普科技股份有限公司 A kind of based reminding method and device of shared drive leakage
CN108984295A (en) * 2018-06-19 2018-12-11 珠海全志科技股份有限公司 Method for recovering internal storage, computer installation and computer readable storage medium
CN109656779A (en) * 2018-12-07 2019-04-19 广州市百果园信息技术有限公司 Internal memory monitoring method, device, terminal and storage medium
CN109933525A (en) * 2019-02-22 2019-06-25 深圳市吉祥腾达科技有限公司 A kind of general method for detecting memory leakage
CN110032464A (en) * 2019-03-15 2019-07-19 北京星网锐捷网络技术有限公司 The processing method and processing device of RAM leakage
CN110059004A (en) * 2019-03-21 2019-07-26 深圳市腾讯信息技术有限公司 A kind of method, apparatus, equipment and the medium of application test
CN110413401A (en) * 2018-04-28 2019-11-05 武汉斗鱼网络科技有限公司 Manage method, storage medium, electronic equipment and the system of global object's memory
CN110618928A (en) * 2019-06-25 2019-12-27 北京无限光场科技有限公司 Memory leak detection method and device, terminal equipment and medium
CN110633190A (en) * 2019-09-26 2019-12-31 北京博睿宏远数据科技股份有限公司 Application program memory monitoring method, device, equipment and storage medium
CN110727585A (en) * 2019-09-11 2020-01-24 锐捷网络股份有限公司 Memory leak detection method and device, electronic equipment and readable storage medium
CN111190833A (en) * 2019-11-26 2020-05-22 腾讯云计算(北京)有限责任公司 Sensitive data detection method and device, storage medium and equipment
CN111597109A (en) * 2020-04-24 2020-08-28 清华大学 Defect detection method and system for cross-architecture firmware stack memory
CN111832022A (en) * 2020-07-03 2020-10-27 北京智游网安科技有限公司 Double Free vulnerability detection method, terminal and storage medium
CN111931191A (en) * 2020-09-09 2020-11-13 中国人民解放军国防科技大学 Dynamic detection method and system for binary software stack overflow leakage hole of Linux platform
CN113157455A (en) * 2021-04-27 2021-07-23 腾讯科技(深圳)有限公司 Memory management method and device, electronic equipment and computer readable storage medium
CN114253825A (en) * 2020-09-22 2022-03-29 腾讯科技(深圳)有限公司 Memory leak detection method and device, computer equipment and storage medium
CN117453446A (en) * 2023-12-15 2024-01-26 荣耀终端有限公司 Auxiliary information acquisition method for memory leakage positioning and electronic equipment

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100095281A1 (en) * 2008-10-14 2010-04-15 Riverside Research Institute Internal Function Debugger
US7761852B2 (en) * 2003-11-26 2010-07-20 International Business Machines Corporation Fast detection of the origins of memory leaks when using pooled resources
CN102073591A (en) * 2011-01-14 2011-05-25 福建星网视易信息系统有限公司 Method and system for detecting memory occupancy state of embedded system
CN102081548A (en) * 2009-11-30 2011-06-01 华为技术有限公司 Method and system for processing Java application and SAF (service availability forum) platform
CN102831068A (en) * 2011-06-13 2012-12-19 阿里巴巴集团控股有限公司 Memory operating record processing method and device
CN103150220A (en) * 2011-12-07 2013-06-12 腾讯科技(深圳)有限公司 Method and system for interprocess communications
CN103294588A (en) * 2012-02-22 2013-09-11 深圳富泰宏精密工业有限公司 Memory detecting system and method
CN103902359A (en) * 2014-03-31 2014-07-02 深圳创维-Rgb电子有限公司 Android based system memory optimizing and application scheduling method and system
US8996743B1 (en) * 2013-09-25 2015-03-31 International Business Machines Corporation Event driven remote direct memory access snapshots
CN104636256A (en) * 2015-02-17 2015-05-20 中国农业银行股份有限公司 Memory access abnormity detecting method and memory access abnormity detecting device

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7761852B2 (en) * 2003-11-26 2010-07-20 International Business Machines Corporation Fast detection of the origins of memory leaks when using pooled resources
US20100095281A1 (en) * 2008-10-14 2010-04-15 Riverside Research Institute Internal Function Debugger
CN102081548A (en) * 2009-11-30 2011-06-01 华为技术有限公司 Method and system for processing Java application and SAF (service availability forum) platform
CN102073591A (en) * 2011-01-14 2011-05-25 福建星网视易信息系统有限公司 Method and system for detecting memory occupancy state of embedded system
CN102831068A (en) * 2011-06-13 2012-12-19 阿里巴巴集团控股有限公司 Memory operating record processing method and device
CN103150220A (en) * 2011-12-07 2013-06-12 腾讯科技(深圳)有限公司 Method and system for interprocess communications
CN103294588A (en) * 2012-02-22 2013-09-11 深圳富泰宏精密工业有限公司 Memory detecting system and method
US8996743B1 (en) * 2013-09-25 2015-03-31 International Business Machines Corporation Event driven remote direct memory access snapshots
CN103902359A (en) * 2014-03-31 2014-07-02 深圳创维-Rgb电子有限公司 Android based system memory optimizing and application scheduling method and system
CN104636256A (en) * 2015-02-17 2015-05-20 中国农业银行股份有限公司 Memory access abnormity detecting method and memory access abnormity detecting device

Cited By (37)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107145447A (en) * 2017-05-09 2017-09-08 网易(杭州)网络有限公司 Detect method, device and the electronic equipment of memory overflow
CN107145447B (en) * 2017-05-09 2020-07-07 网易(杭州)网络有限公司 Method and device for detecting memory leakage and electronic equipment
CN107360317A (en) * 2017-06-29 2017-11-17 努比亚技术有限公司 The detection method and mobile terminal, storage medium of application resource leakage
CN107480047A (en) * 2017-07-13 2017-12-15 珠海金山网络游戏科技有限公司 A kind of method and device of internal memory auto snapshot
CN107908539A (en) * 2017-07-24 2018-04-13 平安科技(深圳)有限公司 A kind of method, terminal and computer-readable recording medium for detecting application program RAM leakage
CN107908539B (en) * 2017-07-24 2020-07-17 平安科技(深圳)有限公司 Method, terminal and computer readable storage medium for detecting memory leakage of application program
CN107562586A (en) * 2017-08-16 2018-01-09 努比亚技术有限公司 A kind of internal-memory detection method, equipment and computer-readable storage medium
CN107797898A (en) * 2017-09-28 2018-03-13 东软集团股份有限公司 Collecting method and its device
CN107797898B (en) * 2017-09-28 2020-11-27 东软集团股份有限公司 Data acquisition method and device thereof
CN108121602A (en) * 2017-12-14 2018-06-05 捷开通讯(深圳)有限公司 A kind of method, electronic equipment and the storage medium of definite garbage collection trigger point
CN108121602B (en) * 2017-12-14 2022-05-06 捷开通讯(深圳)有限公司 Method for determining garbage collection trigger point, electronic equipment and storage medium
CN108108258A (en) * 2017-12-29 2018-06-01 杭州迪普科技股份有限公司 The restorative procedure and device of a kind of RAM leakage
CN108108258B (en) * 2017-12-29 2020-11-06 杭州迪普科技股份有限公司 Memory leak repairing method and device
CN108334435A (en) * 2018-01-18 2018-07-27 杭州迪普科技股份有限公司 A kind of based reminding method and device of shared drive leakage
CN110413401A (en) * 2018-04-28 2019-11-05 武汉斗鱼网络科技有限公司 Manage method, storage medium, electronic equipment and the system of global object's memory
CN108984295B (en) * 2018-06-19 2020-08-07 珠海全志科技股份有限公司 Memory recovery method, computer device and computer readable storage medium
CN108984295A (en) * 2018-06-19 2018-12-11 珠海全志科技股份有限公司 Method for recovering internal storage, computer installation and computer readable storage medium
CN109656779A (en) * 2018-12-07 2019-04-19 广州市百果园信息技术有限公司 Internal memory monitoring method, device, terminal and storage medium
CN109933525A (en) * 2019-02-22 2019-06-25 深圳市吉祥腾达科技有限公司 A kind of general method for detecting memory leakage
CN110032464A (en) * 2019-03-15 2019-07-19 北京星网锐捷网络技术有限公司 The processing method and processing device of RAM leakage
CN110032464B (en) * 2019-03-15 2023-06-16 北京星网锐捷网络技术有限公司 Memory leakage processing method and device
CN110059004A (en) * 2019-03-21 2019-07-26 深圳市腾讯信息技术有限公司 A kind of method, apparatus, equipment and the medium of application test
CN110618928A (en) * 2019-06-25 2019-12-27 北京无限光场科技有限公司 Memory leak detection method and device, terminal equipment and medium
CN110727585A (en) * 2019-09-11 2020-01-24 锐捷网络股份有限公司 Memory leak detection method and device, electronic equipment and readable storage medium
CN110727585B (en) * 2019-09-11 2023-07-21 锐捷网络股份有限公司 Memory leak detection method, device, electronic equipment and readable storage medium
CN110633190A (en) * 2019-09-26 2019-12-31 北京博睿宏远数据科技股份有限公司 Application program memory monitoring method, device, equipment and storage medium
CN111190833A (en) * 2019-11-26 2020-05-22 腾讯云计算(北京)有限责任公司 Sensitive data detection method and device, storage medium and equipment
CN111190833B (en) * 2019-11-26 2023-03-24 腾讯云计算(北京)有限责任公司 Sensitive data detection method and device, storage medium and equipment
CN111597109B (en) * 2020-04-24 2022-03-11 清华大学 Defect detection method and system for cross-architecture firmware stack memory
CN111597109A (en) * 2020-04-24 2020-08-28 清华大学 Defect detection method and system for cross-architecture firmware stack memory
CN111832022A (en) * 2020-07-03 2020-10-27 北京智游网安科技有限公司 Double Free vulnerability detection method, terminal and storage medium
CN111832022B (en) * 2020-07-03 2024-02-13 北京智游网安科技有限公司 Double Free vulnerability detection method, terminal and storage medium
CN111931191A (en) * 2020-09-09 2020-11-13 中国人民解放军国防科技大学 Dynamic detection method and system for binary software stack overflow leakage hole of Linux platform
CN114253825A (en) * 2020-09-22 2022-03-29 腾讯科技(深圳)有限公司 Memory leak detection method and device, computer equipment and storage medium
CN113157455A (en) * 2021-04-27 2021-07-23 腾讯科技(深圳)有限公司 Memory management method and device, electronic equipment and computer readable storage medium
CN117453446A (en) * 2023-12-15 2024-01-26 荣耀终端有限公司 Auxiliary information acquisition method for memory leakage positioning and electronic equipment
CN117453446B (en) * 2023-12-15 2024-04-26 荣耀终端有限公司 Auxiliary information acquisition method for memory leakage positioning and electronic equipment

Also Published As

Publication number Publication date
CN106610892B (en) 2020-12-22

Similar Documents

Publication Publication Date Title
CN106610892A (en) Memory leak detecting method and device
US9529692B2 (en) Memory management tools
CN107066390B (en) Dynamic memory leak detection method and system
US8418149B2 (en) Differential comparison system and method
CN109656779A (en) Internal memory monitoring method, device, terminal and storage medium
US8196116B2 (en) Tracing objects in object-oriented programming model
JPH09218800A (en) Method and device for analyzing software executed in incorporation system
US10241895B2 (en) Memory stack trace management tool
CN107092678B (en) Method, device and equipment for acquiring application activity degree
CN110955598B (en) Breakpoint processing method and device for kernel mode program
TW201335752A (en) Memory detection system and method
CN109857520B (en) Semantic reconstruction improvement method and system in virtual machine introspection
CN112035314A (en) Memory leakage monitoring method and device and electronic equipment
US11580228B2 (en) Coverage of web application analysis
CN110597704A (en) Application program pressure testing method, device, server and medium
CN107729751A (en) data detection method and device
CN111274060A (en) Method, device, equipment and storage medium for determining memory abnormity
US8145819B2 (en) Method and system for stealing interrupt vectors
US11055209B2 (en) Application analysis with flexible post-processing
CN112612537A (en) Configuration data caching method, device, equipment and storage medium
Ilin et al. Performance analysis of software with a variant NoSQL data schemes
US10496524B2 (en) Separating test coverage in software processes using shared memory
WO2023284877A1 (en) Detection method and apparatus, and electronic device
CN114296986B (en) Memory leakage positioning method, device, medium and electronic equipment
CN112631941B (en) Method and system for locating linux kernel slub memory leakage

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant