Resource detection method and device
By checking and listening to the current view class requested by accessing the page, the leak class is determined, which solves the problem of excessive memory occupancy of resource detection in the existing technology, and achieves the effect of lightweight and fast detection.
Patent Information
- Application Number
- CN202110571590.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-25
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2041-05-25
AI Technical Summary
The prior art occupies a large amount of memory resources when performing resource detection, resulting in the detection process being prone to crash due to insufficient memory allocation, and the effect of lightweight functions cannot be achieved.
By verifying the current view class corresponding to the access page request, and at the end of the listening, the current view class that meets the preset requirements is determined as a leaked class, real-time acquisition of the class name and class address, storing the leaked class in real time, and accurately locate the scope of the leaked class.
It implements detection of classes in a non-reference manner, avoids the problem of excessive memory usage, and can quickly obtain all leaked class collections. It has light functions, making development unaware.
Smart Images

Figure CN113268424B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer software technology, and in particular to a resource detection method and device. Background Art
[0002] During the system development process, some negligence may cause a class to have a memory leak. This class is defined as a leak class. When the memory usage rises to a certain level, the developed application software will crash due to insufficient memory allocation, which greatly affects the user experience. To solve the crash problem, the existing solution uses weak references to the detection class. During the detection, all referenced pointers are stored and then the non-leaked pointers are deleted. Such addition and deletion operations consume a lot of memory and are prone to crashes due to insufficient memory allocation during the detection process, which cannot achieve the purpose of lightweight functions. Summary of the invention
[0003] In view of this, an embodiment of the present invention provides a resource detection method and device to solve the problem of occupying memory resources when performing resource detection in the prior art.
[0004] According to a first aspect, an embodiment of the present invention provides a resource detection method, the method comprising:
[0005] Get access page request;
[0006] Verify the current view class corresponding to the access page request, and when the verification passes, monitor the current view class;
[0007] When the monitoring is finished, the current view class that meets the preset requirements is determined as a leak class to complete the detection of system resources.
[0008] The resource detection method provided by the embodiment of the present invention verifies the current view class corresponding to the access page request, and determines the current view class that meets the preset requirements as a leak class to complete the detection of system resources; it obtains the class name and class address in a non-reference manner, has no invasion of the detected class, stores the leaked class in real time, accurately locates the leaked class range, and determines the specific leaked class with higher efficiency, can quickly obtain all leaked class sets, and has lightweight functions, making development unaware.
[0009] In combination with the first aspect, in a first implementation of the first aspect, the verifying the current view class corresponding to the access page request includes:
[0010] Obtain the class name of the current view class corresponding to the access page request;
[0011] Obtaining a base class of the current view class according to the class name, and determining whether the base class is a preset view class;
[0012] When the base class is a preset view class, determining whether the current view class is a class that meets the execution condition;
[0013] When the current view class is a class that satisfies the execution condition, it is determined that the verification of the current view class is passed.
[0014] In combination with the first implementation of the first aspect, in the second implementation of the first aspect, when the verification passes, monitoring the current view class includes:
[0015] Determine whether there is any leakage class in the leakage class array, and when there is any leakage class in the leakage class array, obtain pages and page names corresponding to all leakage classes in the leakage class array;
[0016] Determine whether the page exists in the leaked page array, and when the page exists in the leaked page array, determine the leaked subview in the leaked subview array according to the page name;
[0017] When the base class of the current view class is consistent with the class name of the leaked subview, the level of the class name of the leaked subview is increased by one level to determine the level of the data corresponding to the current view class, and the current view class is stored in the leaked subview array to determine the end of monitoring.
[0018] In combination with the second implementation of the first aspect, in the third implementation of the first aspect, when the base class of the current view class is inconsistent with the class name of the leaked sub-view, the hierarchy of the data corresponding to the current view class is determined to be the first level, and the current view class is stored in the leaked sub-view array to determine that the monitoring is ended.
[0019] In combination with the second implementation of the first aspect, in a fourth implementation of the first aspect, the resource detection method further includes:
[0020] When the page does not exist in the leaked page array, creating a leaked class data model;
[0021] The page data model is added to the leaked page array and the leaked sub-view array, and the level of the data corresponding to the current view class is determined to be the first level, so as to determine that the monitoring is ended.
[0022] In combination with the second implementation of the first aspect, in the fifth implementation of the first aspect, when the monitoring ends, determining the current view class that meets the preset requirements as a leakage class includes:
[0023] When the monitoring ends, the current view class is added to the leaked class array;
[0024] When the execution result of the preset memory destruction function is not obtained, it is determined that the current view class does not meet the preset requirements, and the data in the leaked class array that is consistent with the class name and class address of the current view class is deleted;
[0025] When the execution result of the preset memory destruction function is obtained, the current view class in the leak class array is determined as the leak class.
[0026] In combination with any one of the second to fifth implementations of the first aspect, in a sixth implementation of the first aspect, the resource detection method further includes:
[0027] Traverse the data in the leaked subview array;
[0028] According to different display requirements, the traversed data is grouped and processed to achieve hierarchical display of the data in the leaked subview array.
[0029] The resource detection method provided by the embodiment of the present invention uses a tree structure to display the results and the leaked pages in a sorted manner, so that leakage problems can be easily viewed and leakage categories can be viewed in real time.
[0030] In combination with the sixth implementation manner of the first aspect, in the seventh implementation manner of the first aspect, when the display requirement is data-level result display, grouping the traversed data according to different display requirements includes:
[0031] Determine the root node using the name of the page;
[0032] Obtain the sub-view name in the leaked sub-view array, and determine the data in the first-level data that is consistent with the name of the page as the child node corresponding to the root node;
[0033] The data in the second-level data that has the same class name as the leaked class in the first-level data is determined as the second-level child node corresponding to the child node until the traversal of all data in the leaked subview array is completed.
[0034] In combination with the sixth implementation of the first aspect, in the eighth implementation of the first aspect, when the display requirement is page-level result display, grouping the traversed data according to different display requirements includes:
[0035] Determine the name of the page as the display page name;
[0036] Get the number of data at each level in the leaked subview array;
[0037] The weight of the current level is calculated using the number, and the display pages are sorted according to the weight and the display page name.
[0038] According to a second aspect, an embodiment of the present invention further provides a resource detection device, the device comprising:
[0039] The acquisition module is used to obtain access page requests;
[0040] A monitoring module, used to verify the current view class corresponding to the access page request, and monitor the current view class when the verification passes;
[0041] The processing module is used to determine the current view class that meets the preset requirements as a leakage class when the monitoring is completed, so as to complete the detection of system resources.
[0042] According to the third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the resource detection method described in the first aspect or any one of the embodiments of the first aspect by executing the computer instructions.
[0043] According to a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the resource detection method described in the first aspect or any one of the implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 is a flow chart of a resource detection method according to an embodiment of the present invention;
[0046] Figure 2 is a schematic diagram of a leakage data model according to an embodiment of the present invention;
[0047] Figure 3 is a schematic diagram of a leakage view and a sub-view data model according to an embodiment of the present invention;
[0048] Figure 4 is another flow chart of a resource detection method according to an embodiment of the present invention;
[0049] Figure 5 is another specific flow chart of the resource detection method according to an embodiment of the present invention;
[0050] Figure 6 is another specific example flow chart of the resource detection method according to an embodiment of the present invention;
[0051] Figure 7 is a structural block diagram of a resource detection device according to an embodiment of the present invention;
[0052] Figure 8 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0054] The resource detection method provided in the embodiment of the present invention can be applied to any scenario where it is necessary to detect the system occupied resources, for example, the development of mobile device Android system, iOS system, etc., and no limitation is made to the specific application scenario involved in resource detection. In the following description, the development of iOS system is taken as an example.
[0055] During each demand development process of the iOS system, some negligence may cause the used memory to not be released. When the memory increases to a certain level, the APP will crash due to insufficient memory allocation, which greatly affects the user experience. At present, there are solutions on the market that weakly introduce the detection class, which is invasive. During the detection, all referenced pointers will be stored, and then the pointers that have not been leaked will be deleted. Such addition and deletion operations will consume a lot of memory, and it is easy to crash due to insufficient memory allocation during the detection process, and it cannot achieve the effect of lightweight function. Therefore, an embodiment of the present invention provides a resource detection method.
[0056] In actual applications, after entering a certain page each time, if the code has no memory leak, the system dealloc function (view destruction function) will be executed after leaving the page. If the code has a memory leak, the system dealloc function will not be executed, resulting in increased memory. For example, when opening the APP, before entering a certain page, the APP occupies 8M of memory. After entering a certain page, the APP occupies 10M of memory, so the current page occupies 2M of memory. After exiting the page, theoretically, the APP should occupy 8M of memory. If it is greater than 8M, it is a memory leak.
[0057] According to an embodiment of the present invention, an embodiment of a resource detection method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0058] In this embodiment, a resource detection method is provided, which can be used for the above-mentioned electronic devices, such as computers, mobile phones, tablet computers, etc. Figure 1 is a flow chart of a resource detection method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0059] S11, obtaining an access page request.
[0060] Specifically, before obtaining a request to access a page, this embodiment will pre-formulate a data model of the leakage class and a data model of the leakage page, create a category that monitors the life cycle function of the class, and formulate rules for verifying the leakage class; then, after the verification rules are passed when entering the page, the storage leakage class array is analyzed, and the leakage class model is classified by page latitude, and information such as the class name and class address is obtained in a non-reference manner, and a data model is created and added to the storage leakage class array.
[0061] The specific definition of each data model stage includes:
[0062] 1. Define the leakage data model, where the leakage data model is as follows Figure 2 As shown,
[0063] Class name (class_name): defines the name of the class;
[0064] Class address (class_address): the memory address occupied after the class is created;
[0065] Class life cycle status (class_life_status): corresponds to the system life cycle, see the following description for details;
[0066] Parent class name (superview_name): the parent (base class) class name of the current class;
[0067] Outermost page class name (vc_name): the viewcontroller class name of the outermost page, used to classify page display;
[0068] Level: The leaked view level of the VC page;
[0069] Weight: View level and corresponding number of leaks.
[0070] 2. Define the leaking VC and subview data model, where the leaking VC (leaking view) and subview data model are as follows Figure 3 As shown,
[0071] Page class name (vc_name): the viewcontroller class name of the current VC page;
[0072] Weight: the sum of the weights of the subviews in the VC page;
[0073] Subview array (subviews_array): stores the leaked views in the current VC page.
[0074] 3. Define the leak class array: leaksModelArray; the leak class array mainly stores the data model of the leak class. If the detected class does not execute dealloc, create a leak class data model and store the data model in this array.
[0075] 4. Define the array for storing leaked VC and sub-views: leaksVCArray; leaked page array and leaked sub-view array. If there is a view leak in the VC page, the leaked views will be counted based on the latitude of the VC page, and a leaked page data model will be created. The leaked page data model will be stored in the leaked page array. If there is a memory leak in the sub-view, a leaked sub-view data model will be created and stored in the leaked sub-view array.
[0076] 5. Define the ignore detection class rules (execution conditions): for example, specify the class name, start with custom characters, end with custom characters, project path, whether a certain method is executed, and perform precise filtering and detection and store them in an array.
[0077] It should be noted that the form of each data model listed above is only a schematic description, and the specific form can be set accordingly according to actual conditions, and no limitation is made here.
[0078] S12, verifying the current view class corresponding to the access page request, and monitoring the current view class when the verification passes.
[0079] When a page is accessed and a request for the accessed page is obtained, the current view class corresponding to the request for the accessed page is verified. The specific verification process will be described below. When the verification passes, the current view class is monitored to determine whether the current view class is a leaking class. It should be noted that in this embodiment, the current view class corresponding to all requests is defaulted to a temporary leaking class, and then whether it is a leaking class is finally determined based on subsequent monitoring results.
[0080] S13, when the monitoring is finished, the current view class that meets the preset requirements is determined as a leak class to complete the detection of system resources. The previous text also specifically explains that if the code has no memory leak, the system dealloc function must be executed after leaving the page. If the code has a memory leak, the system dealloc function will not be executed. In this embodiment, after the monitoring is finished, the class that does not execute the system dealloc function is determined as a leak class to clarify the memory occupied by the current system and complete the detection of system resources.
[0081] This step will be described in detail below.
[0082] The resource detection method provided in this embodiment verifies the current view class corresponding to the access page request, and determines the current view class that meets the preset requirements as a leaking class to complete the detection of system resources; it obtains the class name and class address in a non-reference manner, has no invasion of the detected class, stores the leaking class in real time, accurately locates the scope of the leaking class, and determines the specific leaking class with higher efficiency, and can quickly obtain all leaking class sets. The function is lightweight and makes development unaware.
[0083] In this embodiment, a resource detection method is provided, which can be used for the above-mentioned electronic devices, such as computers, mobile phones, tablet computers, etc. Figure 4 is a flow chart of a resource detection method according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:
[0084] S21, obtaining an access page request.
[0085] For details, please see Figure 1 S11 of the illustrated embodiment will not be described in detail here.
[0086] S22, verify the current view class corresponding to the access page request, and when the verification passes, monitor the current view class.
[0087] Specifically, the verification of the current view class corresponding to the access page request in S22 includes the following steps:
[0088] S220, obtaining the class name of the current view class corresponding to the access page request.
[0089] Specifically, the class name of the current view class is obtained in the form of a string. After obtaining the class name of the current view class, this embodiment will determine whether the byte length of the string corresponding to the class name of the current view class is greater than 0. If it is not greater than 0 (less than or equal to 0), it means that the class name has not been obtained. If the class name has not been obtained, no subsequent detection will be performed on the view. Similarly, the class address corresponding to the current view class can also be determined by the number of bytes of the class address string. It should be noted that in this embodiment, only the number of bytes of the class name is determined to determine whether the class name is obtained. In actual applications, the class name can also be directly obtained in the request data at will, and this embodiment is not limited to this.
[0090] S221, obtaining the base class of the current view class according to the class name, and determining whether the base class is a preset view class.
[0091] The base class of the current view class is determined according to the pre-defined leakage class data model. Only when the base class of the current view class is the UIView class (the preset view class) can the current view class be determined to be the actual view class. All view classes will be built into the UIView class.
[0092] S222: When the base class is a preset view class, determine whether the current view class is a class that meets the execution condition.
[0093] In this embodiment, according to the predefined ignore detection class rule, it is determined whether the current view class exists in the ignore detection class array, or satisfies the ignore detection class rule, indicating that the current view class needs to be ignored without subsequent detection.
[0094] S223: When the current view class is a class that meets the execution condition, it is determined that the verification of the current view class is passed.
[0095] Specifically, when the verification is passed in the above S22, monitoring the current view class includes the following steps:
[0096] S224, when the verification passes, determine whether there is any leak class in the leak class array, and when there is any leak class in the leak class array, obtain the pages and page names corresponding to all leak classes in the leak class array.
[0097] When entering a specific page, the system life cycle state continues from the beginning to the end and destruction. The system will execute didMoveToSuperview and call this method when adding to the parent view; then when leaving the current page, didMoveToSuperview will be executed again, that is, it will be moved out of the current parent view; then when the current page is ended, the system will execute dealloc, destroy the view, and release the occupied memory.
[0098] Check whether there is a leak class in the leak class array, that is, check whether the array quantity of leaksModelArray (stored leak class array) is greater than 0; if the array quantity is greater than 0, traverse leaksModelArray (stored leak class array), take the vc_name (VC page name) of each leak class data model in the array to check whether there is a corresponding page name vc_name (VC page name) in leaksVCArray (stored leak VC and subview array).
[0099] S225 , determining whether there is a page in the leaked page array, and when there is a page in the leaked page array, determining a leaked sub-view in the leaked sub-view array according to the page name.
[0100] By checking whether there is a corresponding page name vc_name (page name) in leaksVCArray (stored leaked view array and sub-view array), it is determined whether there is a page in the leaked page array. If there is vc_name (VC page name), traverse the subviews_array (stored leaked sub-view array) corresponding to vc_name (VC page name) in leaksVCArray (stored leaked view array and sub-view array).
[0101] S226, when there is no page in the leak page array, create a leak class data model, that is, check if the array quantity of leaksModelArray (stored leak class array) is 0, create model (leak class data model) and add it to leaksModelArray (stored leak class array) by default.
[0102] S227, adding the page data model to the leaked page array and the leaked sub-view array, determining that the level of the data corresponding to the current view class is the first level, so as to determine that the monitoring is ended.
[0103] S228, when the base class of the current view class is consistent with the class name of the leaked subview, the level of the class name of the leaked subview is increased by one level to determine it as the level of the data corresponding to the current view class, and the current view class is stored in the leaked subview array to determine the end of monitoring.
[0104] Specifically, when the superview_name (parent class name) of the data model is consistent with the class_name (class name) in the subviews_array (subview array), the level of the model (leaked class data model) is increased by 1, added to the subviews_array (subview array), and the monitoring ends.
[0105] S229, when the base class of the current view class is inconsistent with the class name of the leaked subview, determine that the level of the data corresponding to the current view class is the first level, and store the current view class in the leaked subview array to determine that the monitoring is ended.
[0106] S23, when the monitoring is finished, the current view class that meets the preset requirements is determined as a leak class to complete the detection of system resources.
[0107] For details, please see Figure 1 S13 of the illustrated embodiment will not be described in detail here.
[0108] The resource detection method provided in this embodiment verifies the current view class corresponding to the access page request, and determines the current view class that meets the preset requirements as a leaking class to complete the detection of system resources; it obtains the class name and class address in a non-reference manner, has no invasion of the detected class, stores the leaking class in real time, accurately locates the scope of the leaking class, and determines the specific leaking class with higher efficiency, and can quickly obtain all leaking class sets. The function is lightweight and makes development unaware.
[0109] In this embodiment, a resource detection method is provided, which can be used for the above-mentioned electronic devices, such as computers, mobile phones, tablet computers, etc. Figure 5 is a flow chart of a resource detection method according to an embodiment of the present invention. Figure 5 As shown, the process includes the following steps:
[0110] S31, obtaining an access page request.
[0111] For details, please see Figure 4 S21 of the illustrated embodiment will not be described in detail here.
[0112] S32, verifying the current view class corresponding to the access page request, and monitoring the current view class when the verification passes.
[0113] For details, please see Figure 4 S22 of the illustrated embodiment will not be described in detail here.
[0114] S33, when the monitoring is finished, the current view class that meets the preset requirements is determined as a leak class to complete the detection of system resources.
[0115] Specifically, the above S33 includes the following steps:
[0116] S331, when the monitoring is finished, the current view class is added to the leaked class array. After the monitoring is finished, the current view class is directly added to the leaked class array by default, and then it is determined whether the preset requirements are met, that is, whether the preset memory destruction function (dealloc) is executed.
[0117] S332, when the execution result of the preset memory destruction function is not obtained, it is determined that the current view class does not meet the preset requirements, and the data in the leaked class array that is consistent with the class name and class address of the current view class is deleted.
[0118] S333: When the execution result of the preset memory destruction function is obtained, the current view class in the leak class array is determined as the leak class.
[0119] The resource detection method provided in this embodiment verifies the current view class corresponding to the access page request, and determines the current view class that meets the preset requirements as a leaking class to complete the detection of system resources; it obtains the class name and class address in a non-reference manner, has no invasion of the detected class, stores the leaking class in real time, accurately locates the scope of the leaking class, and determines the specific leaking class with higher efficiency, and can quickly obtain all leaking class sets. The function is lightweight and makes development unaware.
[0120] In this embodiment, a resource detection method is provided, which can be used for the above-mentioned electronic devices, such as computers, mobile phones, tablet computers, etc. Figure 6 is a flow chart of a resource detection method according to an embodiment of the present invention. Figure 6 As shown, the process includes the following steps:
[0121] S41, obtaining an access page request.
[0122] For details, please see Figure 5 S31 of the illustrated embodiment will not be described in detail here.
[0123] S42, verifying the current view class corresponding to the access page request, and monitoring the current view class when the verification passes.
[0124] For details, please see Figure 5 S32 of the illustrated embodiment will not be described in detail here.
[0125] S43, when the monitoring is finished, the current view class that meets the preset requirements is determined as a leak class to complete the detection of system resources.
[0126] For details, please see Figure 5 S32 of the illustrated embodiment will not be described in detail here.
[0127] In order to display the results in a hierarchical manner, which is beneficial to the subsequent resource search work and the subsequent memory resource release work, the resource detection method provided in this embodiment also includes:
[0128] S44, traverse the data in the leaked subview array. Traverse the leaksVCArray (stored leaked view array and subview array), and extract the leaked VC and subview data models one by one.
[0129] S45, grouping the traversed data according to different display requirements to achieve hierarchical display of the data in the leaked subview array.
[0130] Specifically, when the display requirement is data-level result display, all stored leakage class data are displayed in a tree structure. The above step S45 includes the following steps:
[0131] S451, determine the root node using the page name; use vc_name as the root node of the tree and start assigning subtree nodes.
[0132] S452, obtain the subview name in the leaked subview array, determine the data in the first-level data that is consistent with the page name as the child node corresponding to the root node; sort subviews_array from small to large level, traverse subviews_array, and assign the data model with level=1 to the subtree node of vc_name respectively. Record the data model class_name that has been found, and remove the data model that has been found from the array.
[0133] S453, determine the data in the second level data that has the same class name as the leaked class in the first level data as the second level child node corresponding to the child node, until the traversal of all data in the leaked subview array is completed. Continue to traverse downwards, compare with the superview_name of the data model in the remaining array, and connect them into a tree graph structure.
[0134] In another specific embodiment, when the display requirement is page-level result display, each page is displayed at different levels, and the above step S45 includes the following steps:
[0135] S454, determine the name of the page as the display page name, traverse the leaksVCArray, and take vc_name as the page name.
[0136] S455, obtaining the number of data at each level in the leaked subview array.
[0137] S456, using the number to calculate the weight of the current level, and sorting the display pages according to the weight and the display page name. For example: there are many view levels on a page, if there is a memory leak in a certain level of view, the current level (first level or second level) can be obtained, and finally it can be known how many levels of views in a page have memory leaks; if a page has three levels of views, the first level leaks 5 views, and the second level leaks 3 views, then the weight of the first level is greater than the second level (5>3).
[0138] The resource detection method provided in this embodiment verifies the current view class corresponding to the access page request, and determines the current view class that meets the preset requirements as a leaking class to complete the detection of system resources; it obtains the class name and class address in a non-reference manner, has no invasion of the detected class, stores the leaking class in real time, accurately locates the scope of the leaking class, and determines the specific leaking class with higher efficiency, and can quickly obtain all leaking class sets. The function is lightweight and the development is unaware; the results are displayed in a tree structure and the leaking pages are sorted and displayed, so that leakage problems can be easily viewed and the leaking class can be viewed in real time.
[0139] In this embodiment, a resource detection device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0140] This embodiment provides a resource detection device, such as Figure 7 As shown, including:
[0141] Acquisition module 1, used to obtain access page request;
[0142] Monitoring module 2 is used to verify the current view class corresponding to the access page request, and when the verification passes, monitor the current view class;
[0143] The processing module 3 is used to determine the current view class that meets the preset requirements as a leak class when the monitoring is completed, so as to complete the detection of system resources.
[0144] For the specific processes of the above modules, please refer to the relevant description of the resource detection method in another embodiment of the present invention, which will not be repeated here.
[0145] The resource detection device provided in this embodiment verifies the current view class corresponding to the access page request, and determines the current view class that meets the preset requirements as a leak class to complete the detection of system resources; it obtains the class name and class address in a non-reference manner, has no invasion of the detected class, stores the leaked class in real time, accurately locates the scope of the leaked class, and determines the specific leaked class with higher efficiency, can quickly obtain all leaked class sets, and has lightweight functions, making development unaware.
[0146] The resource detection device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC circuit, a processor and a memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0147] The further functional description of each of the above modules is the same as that of the above corresponding embodiments and will not be repeated here.
[0148] The embodiment of the present invention also provides an electronic device having the above Figure 7 The resource detection device shown.
[0149] See also Figure 8 , Figure 8 is a schematic diagram of the structure of an electronic device provided by an optional embodiment of the present invention, such as Figure 8 As shown, the electronic device may include: at least one processor 51, such as a CPU (Central Processing Unit), at least one communication interface 53, a memory 54, and at least one communication bus 52. The communication bus 52 is used to realize the connection and communication between these components. The communication interface 53 may include a display screen (Display) and a keyboard (Keyboard), and the optional communication interface 53 may also include a standard wired interface and a wireless interface. The memory 54 may be a high-speed RAM memory (Random Access Memory) or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 54 may optionally be at least one storage device located away from the aforementioned processor 51. The processor 51 may be combined with Figure 7 In the described device, the memory 54 stores an application program, and the processor 51 calls the program code stored in the memory 54 to execute any of the above method steps.
[0150] The communication bus 52 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 52 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0151] Among them, the memory 54 may include a volatile memory (English: volatile memory), such as a random access memory (English: random-access memory, abbreviated: RAM); the memory may also include a non-volatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk drive (English: hard disk drive, abbreviated: HDD) or a solid-state drive (English: solid-state drive, abbreviated: SSD); the memory 54 may also include a combination of the above types of memory.
[0152] The processor 51 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP.
[0153] The processor 51 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0154] Optionally, the memory 54 is also used to store program instructions. The processor 51 can call the program instructions to implement the present application Figure 1 , 4 , 5 and 6 are resource detection methods shown in embodiments.
[0155] The embodiment of the present invention also provides a non-transitory computer storage medium, which stores computer executable instructions, and the computer executable instructions can execute the resource detection method in any of the above method embodiments. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.
[0156] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A resource detection method, It is characterized in that The method comprises: Get access page request; Verify the current view class corresponding to the access page request, and when the verification passes, monitor the current view class; When the verification passes, monitoring the current view class includes: When the check is passed, determine whether there is any leak class in the leak class array. When there is any leak class in the leak class array, obtain the pages and page names corresponding to all leak classes in the leak class array; determine whether the page exists in the leak page array. When the page exists in the leak page array, determine the leak subview in the leak subview array according to the page name; When the base class of the current view class is consistent with the class name of the leaking subview, the level of the class name of the leaking subview is increased by one level to be determined as the level of the data corresponding to the current view class, and the current view class is stored in the leaking subview array to determine the end of monitoring; When the base class of the current view class is inconsistent with the class name of the leaked subview, determining that the level of the data corresponding to the current view class is the first level, and storing the current view class in the leaked subview array to determine that the monitoring is ended; When the page does not exist in the leaked page array, create a leaked class data model; add the leaked class data model to the leaked page array and the leaked subview array, and determine that the level of the data corresponding to the current view class is the first level, so as to determine that the monitoring is ended; When the monitoring is finished, the current view class that meets the preset requirements is determined as a leak class to complete the detection of system resources.
2. The method according to claim 1, It is characterized in that The verifying the current view class corresponding to the access page request includes: Obtain the class name of the current view class corresponding to the access page request; Obtaining a base class of the current view class according to the class name, and determining whether the base class is a preset view class; When the base class is a preset view class, determining whether the current view class is a class that meets the execution condition; When the current view class is a class that satisfies the execution condition, it is determined that the verification of the current view class is passed.
3. The method according to claim 1, It is characterized in that When the monitoring ends, determining the current view class that meets the preset requirements as a leak class includes: When the monitoring ends, the current view class is added to the leaked class array; When the execution result of the preset memory destruction function is not obtained, it is determined that the current view class does not meet the preset requirements, and the data in the leaked class array that is consistent with the class name and class address of the current view class is deleted; When the execution result of the preset memory destruction function is obtained, the current view class in the leak class array is determined as the leak class.
4. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: Traverse the data in the leaked subview array; According to different display requirements, the traversed data is grouped and processed to achieve hierarchical display of the data in the leaked subview array.
5. The method according to claim 4, It is characterized in that When the display requirement is data-level result display, the traversed data is grouped according to different display requirements, including: Determine the root node using the name of the page; Obtain the sub-view name in the leaked sub-view array, and determine the data in the first-level data that is consistent with the name of the page as the child node corresponding to the root node; The data in the second-level data that has the same class name as the leaked class in the first-level data is determined as the second-level child node corresponding to the child node until the traversal of all data in the leaked subview array is completed.
6. The method according to claim 4, It is characterized in that When the display requirement is page-level result display, the traversed data is grouped according to different display requirements, including: Determine the name of the page as the display page name; Get the number of data at each level in the leaked subview array; The weight of the current level is calculated using the number, and the display pages are sorted according to the weight and the display page name.
7. A resource detection device, It is characterized in that The device comprises: The acquisition module is used to obtain access page requests; A monitoring module, used to verify the current view class corresponding to the access page request, and monitor the current view class when the verification passes; The monitoring module comprises: A judgment submodule, used for judging whether there is any leakage class in the leakage class array when the verification is passed, and when there is any leakage class in the leakage class array, obtaining pages and page names corresponding to all leakage classes in the leakage class array; judging whether the page exists in the leakage page array, and when the page exists in the leakage page array, determining the leakage subview in the leakage subview array according to the page name; An adding submodule is used for, when the base class of the current view class is consistent with the class name of the leaking subview, increasing the level of the class name of the leaking subview by one level to determine it as the level of the data corresponding to the current view class, and storing the current view class in the leaking subview array to determine the end of monitoring; A determination submodule, used for determining that the level of the data corresponding to the current view class is the first level when the base class of the current view class is inconsistent with the class name of the leaked subview, and storing the current view class in the leaked subview array to determine that the monitoring is ended; A submodule is created, which is used to create a leakage class data model when the page does not exist in the leakage page array; the leakage class data model is added to the leakage page array and the leakage subview array, and the level of the data corresponding to the current view class is determined to be the first level, so as to determine that the monitoring is ended; The processing module is used to determine the current view class that meets the preset requirements as a leakage class when the monitoring is completed, so as to complete the detection of system resources.
Citation Information
Patent Citations
Method and device for monitoring leakage of memory
CN104182320A
Method and system for dynamically detecting C / C++ memory leak
CN105912458A