A method and device for determining wild pointer
By generating monitoring subclasses for target objects and monitoring whether their memory space is recycled, the problem of difficult recognition of wild pointers in the IOS system is solved, and the timely identification and processing of wild pointers is realized, avoiding system crashes.
Patent Information
- Application Number
- CN202210621460.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-02
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2042-06-02
AI Technical Summary
In IOS systems, crashes caused by wild pointers are difficult to detect and locate in a timely manner. The existing technology lacks effective solutions, which leads to crashes that are difficult to deal with when exposed in an online environment.
Generate monitoring subclasses for the target object. By monitoring the subclass, monitor whether the memory space pointed to by the target object has been recycled, determine whether the pointer is a wild pointer, and send a recycling message to notify the pointer that the memory space has been recycled, avoiding the pointer pointing to the recycled memory space.
It realizes timely and efficient identification of field pointers, reduces the possibility of system crashes, improves the efficiency of crash discovery in the development stage, and avoids system crashes in the online environment.
Smart Images

Figure CN114860499B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for determining a wild pointer. Background Art
[0002] In iOS, regular crashes are rare. Generally, they occur due to a lack of stable reproduction or valid information. Statistics show that over 60% of the remaining untraceable and unresolvable crashes are caused by dangling pointers. A dangling pointer is a pointer to a deleted object or restricted memory area. This often happens when the memory pointed to by the pointer has been reclaimed elsewhere, but the pointer remains unaware of the memory and continues to point to it.
[0003] During normal development, testing, and grayscale testing, various crashes will be encountered. Some crashes can be discovered in time, but some crashes are very hidden and not easy to find during testing. They are easily exposed only in the online production environment, but it is too late to discover them in the online production environment. Therefore, it is necessary to locate crashes as early as possible in the early stages of development and handle them as soon as possible.
[0004] Currently, no effective solution has been proposed to promptly and effectively detect crashes caused by wild pointers. Summary of the Invention
[0005] The purpose of this application is to provide a method and device for determining wild pointers, which can realize timely and efficient identification of wild pointers to reduce the possibility of system crashes.
[0006] The present application provides a method and device for determining an outdated pointer, which is implemented as follows:
[0007] A method for determining a wild pointer, the method comprising:
[0008] Controlling a monitoring subclass to monitor whether the memory space pointed to by a target object is reclaimed, wherein the monitoring subclass is a subclass generated for the target object and points to the same memory space as the target object;
[0009] In a case where it is determined that the memory space pointed to by the target object is reclaimed, determining that the pointer pointing to the target object is a wild pointer;
[0010] The monitoring subclass is controlled to send a reclaim message to the pointer pointing to the target object, so as to notify the pointer that the memory space of the target object has been reclaimed.
[0011] In one embodiment, before the control monitoring subclass monitors whether the memory space pointed to by the target object is reclaimed, the method further includes:
[0012] Determine whether the target object is an immediately destructible object;
[0013] In the case where it is determined that the target object is an object of the immediate destruction class, the monitoring subclass is generated for the target object, wherein the monitoring subclass and the target object point to the same memory space.
[0014] In one embodiment, after controlling the monitoring subclass to send a reclaim message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been reclaimed, the method further includes:
[0015] Using a pointer to the target object as a target pointer;
[0016] The target pointer is controlled to point to a non-reclaimed memory space, or the target pointer is controlled to point to the memory space of a specific object.
[0017] In one embodiment, controlling the monitoring subclass to send a reclaim message to the pointer pointing to the target object includes:
[0018] The monitoring subclass is controlled to call the underlying C language, and the recovery message is sent through the C language code.
[0019] In one embodiment, the monitoring subclass and the target object both inherit from the NSObject class.
[0020] In one embodiment, the application is in an IOS system.
[0021] A device for determining an out-of-range pointer, comprising:
[0022] A first control module is used to control a monitoring subclass to monitor whether the memory space pointed to by the target object is recycled, wherein the monitoring subclass is a subclass generated for the target object and points to the same memory space as the target object;
[0023] A first determining module is configured to determine that the pointer pointing to the target object is a wild pointer when it is determined that the memory space pointed to by the target object is reclaimed;
[0024] The second control module is configured to control the monitoring subclass to send a reclaim message to the pointer pointing to the target object, so as to notify the pointer that the memory space of the target object has been reclaimed.
[0025] In one embodiment, the above device further comprises:
[0026] A second determining module is used to determine whether the target object is an immediate destruction class object before the control monitoring subclass monitors whether the memory space pointed to by the target object is recycled;
[0027] A generation module is used to generate the monitoring subclass for the target object when it is determined that the target object is an object of the immediate destruction class, wherein the monitoring subclass and the target object point to the same memory space.
[0028] An electronic device comprises a processor and a memory for storing instructions executable by the processor, wherein the steps of the above method are implemented when the processor executes the instructions.
[0029] A computer-readable storage medium stores computer instructions, which implement the steps of the above method when executed.
[0030] The method and device for identifying orphan pointers provided in this application generate a one-to-one corresponding monitoring subclass for a target object. This monitoring subclass then monitors whether the memory space pointed to by the target object has been reclaimed, thereby promptly determining whether the pointer corresponding to the target object is an orphan pointer. This solution solves the existing problem of orphan pointers being unable to be effectively identified, which can lead to system crashes. It achieves the technical effect of efficiently and promptly identifying orphan pointers, thereby preventing system crashes. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0032] Figure 1 This is a method flow chart of an embodiment of a method for determining a wild pointer provided by the present application;
[0033] Figure 2 This is a diagram of the relationship between wild pointers, objects, and subclasses provided by this application;
[0034] Figure 3 This is a hardware structure block diagram of an electronic device for a method for determining a wild pointer provided by the present application;
[0035] Figure 4 This is a structural block diagram of an embodiment of a device for determining a wild pointer provided in this application. DETAILED DESCRIPTION
[0036] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0037] In order to solve the existing problem that wild pointers cannot be discovered in a timely and efficient manner, which leads to system crashes, in this example, it is considered that a monitoring subclass can be generated for the target object. The monitoring subclass points to the same memory space as the target object. In this way, the monitoring subclass can be used to sniff whether the memory space pointed to by the target object has been recycled.
[0038] Figure 1 It is a method flow chart of an embodiment of the method for determining a wild pointer provided by the present application. Although the present application provides method operation steps or device structures as shown in the following embodiments or drawings, more or fewer operation steps or module units may be included in the method or device based on routine or no creative labor. In the steps or structures where there is no necessary causal relationship logically, the execution order of these steps or the module structure of the device is not limited to the execution order or module structure described in the embodiments of the present application and shown in the drawings. When the method or module structure is applied to an actual device or terminal product, it can be connected in accordance with the method or module structure shown in the embodiment or drawings for sequential execution or parallel execution (for example, a parallel processor or multi-threaded processing environment, or even a distributed processing environment).
[0039] Specifically, such as Figure 1 As shown, the above method for determining a wild pointer may include the following steps:
[0040] Step 101: Controlling a monitoring subclass to monitor whether the memory space pointed to by a target object is recycled, wherein the monitoring subclass is a subclass generated for the target object and points to the same memory space as the target object;
[0041] That is, write a proxy class inherited from the NSObject class for each target object that needs to be monitored, and use the newly written proxy class to track the entire process of the object's destruction. The proxy class points to the memory space of the object, so as to finally confirm whether the memory space of the object has been reclaimed, thereby locating the wild pointer.
[0042] Step 102: When it is determined that the memory space pointed to by the target object is reclaimed, determining that the pointer pointing to the target object is a wild pointer;
[0043] For example: suppose there is a pointer A, which points to object B. The hexadecimal address of object B's memory space is 0x11. Because object B is a class that needs to be destroyed at any time, pointer A may be a wild pointer. Therefore, it is necessary to locate the pointer because pointer A is where the crash may occur. To this end, a subclass C can be written for object B. Subclass C inherits from the NSObject class. Because any object in the iOS code is a subclass of NSObject, object B is also a subclass of NSObject. Subclass C can be made to point to the memory space 0x11 of object B. That is, subclass C and object B point to the same storage space. Subclass C acts as a sniffer for object B. Because subclass C and object B point to the same memory space, subclass C can know if there is any change or release in the content space. Therefore, subclass C can be used to sniff whether object B exists or has been recycled.
[0044] Step 103: Control the monitoring subclass to send a reclaim message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been reclaimed.
[0045] Specifically, by generating a one-to-one corresponding monitoring subclass for each target object, and then using that monitoring subclass to monitor whether the memory space pointed to by the target object is reclaimed, it is possible to promptly determine whether the pointer corresponding to the target object is a stray pointer. This solution solves the existing problem of stray pointers being difficult to effectively identify, which can lead to system crashes. It achieves the technical effect of efficiently and promptly identifying stray pointers, thus preventing system crashes.
[0046] Specifically, before the control monitoring subclass monitors whether the memory space pointed to by the target object has been reclaimed, it can determine whether the target object is an immediately destructible object. If the target object is determined to be an immediately destructible object, the monitoring subclass is generated for the target object, where the monitoring subclass and the target object point to the same memory space. This is mainly because immediately destructible objects may be destroyed at any time, while singleton objects have a full lifecycle and are therefore not destroyed. Therefore, in order to reduce the number of monitoring subclass settings, monitoring subclasses can be set only for immediately destructible objects.
[0047] After controlling the monitoring subclass to send a recycling message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been recycled, the pointer pointing to the target object can be used as the target pointer; the target pointer can be controlled to point to a non-recycled memory space, or the target pointer can be controlled to point to the memory space of a specific object.
[0048] That is, for example: through subclass C, it can be sniffed that the memory space 0x11 of object B has been recycled, then subclass C can capture the recycling message of this memory space 0x11, and then the recycling message can be sent to pointer A through methods such as forwardMessage, so that pointer A knows that the memory space 0x11 of object B has been recycled, and thus pointer A can point to a new non-recycled memory space or the memory space of another specified object, thereby avoiding pointer A pointing to the memory space of object B that has been recycled without knowing it, thereby causing a crash.
[0049] Specifically, controlling the monitoring subclass to send a recovery message to the pointer pointing to the target object may be controlling the monitoring subclass to call the underlying C language and send the recovery message through the C language code.
[0050] The above monitoring subclass and the target object may both inherit from the NSObject class.
[0051] Considering that the iOS system is prone to crashes due to wild pointers, the above-mentioned wild pointer determination method can be applied to the iOS system.
[0052] The above method is described below in conjunction with a specific embodiment. However, it should be noted that this specific embodiment is only for better illustrating the present application and does not constitute an improper limitation to the present application.
[0053] Wild pointer crashes often occur during app development, but the crash stack doesn't provide much useful information. Furthermore, reproducing these wild pointer crashes with Xcode tools like Malloc Scribble and Zombie is difficult in iOS engineering practice. Malloc Scribble carries a high risk of filling the memory of released objects. Xcode 9's Malloc Scribble no longer fills the memory addresses of objects after startup. Compared to Malloc Scribble, Zombie doesn't require a crash; as long as a wild pointer points to a zombie object, accessing it again will result in a crash.
[0054] Therefore, if wild pointers can be discovered and processed in a timely manner, crashes that may be caused by wild pointers can be effectively avoided.
[0055] In order to detect wild pointers in time, in this example, it is considered that a proxy class inherited from the NSObject class can be written for each target object that needs to be monitored. The entire process of object destruction is tracked through the newly written proxy class, and the proxy class points to the memory space of the object, so as to finally confirm whether the memory space of the object has been recycled, thereby locating the wild pointer.
[0056] Specifically, the following steps may be included:
[0057] S1: Assume that Figure 2 As shown, there is a pointer A, which points to object B. The hexadecimal address of the memory space of object B is 0x11;
[0058] S2: Because object B is a class that needs to be destroyed at any time, pointer A may be a wild pointer. Therefore, it is necessary to locate the pointer because pointer A is where the crash may occur. To this end, a subclass C can be written for object B;
[0059] Among them, subclass C inherits from the NSObject class. Because any object in the iOS code is a subclass of NSObject, object B is also a subclass of NSObject.
[0060] S3: Let subclass C point to the memory space 0x11 of object B. That is, subclass C and object B point to the same storage space. Subclass C acts as a sniffer for object B. Since subclass C and object B point to the same memory space, subclass C will know if there is any change or release in the content space. Therefore, subclass C can be used to sniff whether object B exists or has been recycled.
[0061] S4: If it is determined that object B has been reclaimed elsewhere, then pointer A points to the memory area of the deleted object B. However, pointer A is unaware that the memory interval 0x11 of object B has been reclaimed because the memory space recycling system does not inform pointer A. As a result, pointer A becomes a wild pointer.
[0062] S5: Through subclass C, it can be detected that the memory space 0x11 of object B has been recycled. Then subclass C can capture the recycling message of this memory space 0x11, and then send the recycling message to pointer A through methods such as forwardMessage. In this way, pointer A knows that the memory space 0x11 of object B has been recycled, so that pointer A can point to a new non-recycled memory space or the memory space of another specified object, thereby avoiding pointer A from pointing to the memory space of object B that has been recycled without knowing it, thereby causing a crash.
[0063] Specifically, when subclass A sends a recovery message to pointer A, it may be possible to send the recovery message to pointer A by calling the underlying C language through Java.
[0064] The above method for determining wild pointers can be used in the debug stage, grayscale stage, and online stage. In particular, it can effectively improve performance in the debug stage, that is, it can achieve the goal of discovering crashes as much as possible while ensuring effective coverage.
[0065] The method embodiments provided in the above embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on an electronic device as an example, Figure 3 This is a hardware structure diagram of an electronic device for determining a wild pointer provided by this application. Figure 3 As shown, the electronic device 10 may include one or more (only one is shown in the figure) processors 02 (the processor 02 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 04 for storing data, and a transmission module 06 for communication functions. It will be understood by those skilled in the art that Figure 3 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 3 More or fewer components than shown, or with Figure 3 Different configurations shown.
[0066] The memory 04 can be used to store software programs and modules of application software, such as the program instructions / modules corresponding to the method for determining a wild pointer in the embodiment of the present application. The processor 02 executes various functional applications and data processing by running the software programs and modules stored in the memory 04, that is, implements the method for determining a wild pointer of the above-mentioned application. The memory 04 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 04 may further include a memory remotely located relative to the processor 02, and these remote memories may be connected to the electronic device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0067] The transmission module 06 is used to receive or send data via a network. Specific examples of the aforementioned network may include a wireless network provided by the communication provider of the electronic device 10. In one embodiment, the transmission module 06 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission module 06 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0068] At the software level, the wild pointer determination device can be as follows: Figure 4 As shown, this may include:
[0069] A first control module 401 is configured to control a monitoring subclass to monitor whether the memory space pointed to by a target object is reclaimed, wherein the monitoring subclass is a subclass generated for the target object and points to the same memory space as the target object;
[0070] A first determining module 402 is configured to determine that a pointer pointing to the target object is a wild pointer when it is determined that the memory space pointed to by the target object is reclaimed;
[0071] The second control module 403 is configured to control the monitoring subclass to send a reclaim message to the pointer pointing to the target object, so as to notify the pointer that the memory space of the target object has been reclaimed.
[0072] In one embodiment, the above-mentioned wild pointer determination device may also include: a second determination module, used to determine whether the target object is an immediate destruction class object before controlling the monitoring subclass to monitor whether the memory space pointed to by the target object is reclaimed; a generation module, used to generate the monitoring subclass for the target object when it is determined that the target object is an immediate destruction class object, wherein the monitoring subclass and the target object point to the same memory space.
[0073] In one embodiment, the monitoring subclass is controlled to send a recycling message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been recycled. The pointer pointing to the target object can also be used as the target pointer; the target pointer is controlled to point to a non-recycled memory space, or the target pointer is controlled to point to the memory space of a specific object.
[0074] In one embodiment, controlling the monitoring subclass to send a reclaim message to the pointer pointing to the target object may include: controlling the monitoring subclass to call an underlying C language and sending the reclaim message through C language code.
[0075] In one embodiment, the monitoring subclass and the target object both inherit from the NSObject class.
[0076] In one embodiment, the above device can be applied in an IOS system.
[0077] The embodiments of the present application also provide a specific implementation of an electronic device capable of implementing all steps in the method for determining a wild pointer in the above embodiment. The electronic device specifically includes the following: a processor, a memory, a communication interface, and a bus; wherein the processor, the memory, and the communication interface communicate with each other via the bus; the processor is configured to call a computer program in the memory, and when the processor executes the computer program, all steps in the method for determining a wild pointer in the above embodiment are implemented. For example, when the processor executes the computer program, the following steps are implemented:
[0078] Step 1: Control the monitoring subclass to monitor whether the memory space pointed to by the target object is recycled, wherein the monitoring subclass is generated for the target object and points to the same memory space as the target object;
[0079] Step 2: When it is determined that the memory space pointed to by the target object is reclaimed, determining that the pointer pointing to the target object is a wild pointer;
[0080] Step 3: Control the monitoring subclass to send a reclaim message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been reclaimed.
[0081] As can be seen from the above description, the embodiments of the present application generate a one-to-one corresponding monitoring subclass for the target object, and then use the monitoring subclass to monitor whether the memory space pointed to by the target object is reclaimed, thereby promptly determining whether the pointer corresponding to the target object is a stray pointer. This solution can solve the problem of existing stray pointers being unable to be effectively identified, which can easily lead to system crashes, and achieve the technical effect of efficiently and promptly identifying stray pointers, thereby avoiding system crashes.
[0082] The embodiments of the present application also provide a computer-readable storage medium capable of implementing all steps of the method for determining a stray pointer in the above embodiment. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the computer program implements all steps of the method for determining a stray pointer in the above embodiment. For example, when the processor executes the computer program, the following steps are implemented:
[0083] Step 1: Control the monitoring subclass to monitor whether the memory space pointed to by the target object is recycled, wherein the monitoring subclass is generated for the target object and points to the same memory space as the target object;
[0084] Step 2: When it is determined that the memory space pointed to by the target object is reclaimed, determining that the pointer pointing to the target object is a wild pointer;
[0085] Step 3: Control the monitoring subclass to send a reclaim message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been reclaimed.
[0086] As can be seen from the above description, the embodiments of the present application generate a one-to-one corresponding monitoring subclass for the target object, and then use the monitoring subclass to monitor whether the memory space pointed to by the target object is reclaimed, thereby promptly determining whether the pointer corresponding to the target object is a stray pointer. This solution can solve the problem of existing stray pointers being unable to be effectively identified, which can easily lead to system crashes, and achieve the technical effect of efficiently and promptly identifying stray pointers, thereby avoiding system crashes.
[0087] The various embodiments in this specification are described in a progressive manner. Similar portions between the various embodiments can be referenced to each other. Each embodiment focuses on the differences between the other embodiments. In particular, the hardware + program embodiments are generally similar to the method embodiments, so their description is relatively simple. For relevant portions, refer to the description of the method embodiments.
[0088] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0089] Although the present application provides method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-creative work. The order of steps listed in the embodiments is only one way of executing the steps among many steps and does not represent the only execution order. When the actual device or client product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, in a parallel processor or multi-threaded processing environment).
[0090] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, an in-vehicle human-computer interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0091] Although the present specification embodiment provides the method operation steps as described in the embodiment or flow chart, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiment is only one way in the order of execution of many steps and does not represent a unique execution order. When the device or terminal product in practice is executed, it can be performed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings (such as a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "comprise", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements not only include those elements, but also include other elements not clearly listed, or also include elements inherent to such process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements.
[0092] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing the embodiments of this specification, the functions of each module can be implemented in the same or multiple software and / or hardware, or the modules that implement the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0093] Those skilled in the art will also appreciate that, in addition to implementing the controller in pure computer-readable program code, it is entirely possible to implement the same functionality by logically programming the method steps in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, and the like. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered structures within the hardware component. Alternatively, the devices for implementing various functions can be considered both software modules implementing the method and structures within the hardware component.
[0094] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0095] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0096] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0097] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0098] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0099] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0100] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, the embodiments of this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0101] Embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. Embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In distributed computing environments, program modules may be located in local and remote computer storage media, including storage devices.
[0102] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between the various embodiments can be referenced across them. Each embodiment focuses on the differences from the other embodiments. In particular, since the system embodiments are generally similar to the method embodiments, their description is relatively simple. For relevant parts, reference can be made to the description of the method embodiments. Throughout this specification, reference to the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of the embodiments in this specification. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples, and features of different embodiments or examples, described in this specification, without conflict.
[0103] The above description is merely an example of the embodiments of this specification and is not intended to limit the embodiments of this specification. For those skilled in the art, various modifications and variations of the embodiments of this specification are possible. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of this specification shall be included within the scope of the claims of the embodiments of this specification.
Claims
1. A method for determining a wild pointer, characterized in that: The method comprises: Controlling a monitoring subclass to monitor whether the memory space pointed to by a target object is reclaimed, wherein the monitoring subclass is a subclass generated for the target object and points to the same memory space as the target object; When it is determined by the monitoring subclass that the memory space pointed to by the target object is reclaimed, determining that the pointer pointing to the target object is a wild pointer; Obtaining a recycling message of the memory space pointed to by the target object through the monitoring subclass, and controlling the monitoring subclass to send a recycling message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been recycled; Wherein, after controlling the monitoring subclass to send a recycling message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been recycled, the method further includes: Using a pointer to the target object as a target pointer; The target pointer is controlled to point to a non-reclaimed memory space, or the target pointer is controlled to point to the memory space of a specific object.
2. The method according to claim 1, characterized in that Before the control monitoring subclass monitors whether the memory space pointed to by the target object is recycled, it also includes: Determine whether the target object is an immediately destructible object; In the case where it is determined that the target object is an object of the immediate destruction class, the monitoring subclass is generated for the target object, wherein the monitoring subclass and the target object point to the same memory space.
3. The method according to claim 1, characterized in that Controlling the monitoring subclass to send a recovery message to the pointer pointing to the target object includes: The monitoring subclass is controlled to call the underlying C language, and the recovery message is sent through the C language code.
4. The method according to any one of claims 1 to 3, characterized in that The monitoring subclass and the target object both inherit from the NSObject class.
5. The method according to any one of claims 1 to 3, characterized in that Applied in IOS system.
6. A device for determining an out-of-range pointer, characterized in that: include: A first control module is used to control a monitoring subclass to monitor whether the memory space pointed to by the target object is recycled, wherein the monitoring subclass is a subclass generated for the target object and points to the same memory space as the target object; a first determining module, configured to determine, when it is determined by the monitoring subclass that the memory space pointed to by the target object is reclaimed, that the pointer pointing to the target object is a wild pointer; A second control module is configured to obtain, through the monitoring subclass, a recycling message of the memory space pointed to by the target object, and control the monitoring subclass to send a recycling message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been recycled; Among them, the monitoring subclass is controlled to send a recycling message to the pointer pointing to the target object to notify the pointer that the memory space of the target object has been recycled, and then the pointer pointing to the target object is used as the target pointer; the target pointer is controlled to point to a non-recycled memory space, or the target pointer is controlled to point to the memory space of a specific object.
7. The device according to claim 6, characterized in that Also includes: A second determining module is used to determine whether the target object is an immediate destruction class object before the control monitoring subclass monitors whether the memory space pointed to by the target object is recycled; A generation module is used to generate the monitoring subclass for the target object when it is determined that the target object is an object of the immediate destruction class, wherein the monitoring subclass and the target object point to the same memory space.
8. An electronic device comprising a processor and a memory for storing instructions executable by the processor, characterized in that: When the processor executes the instructions, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instructions are executed, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Object destruction method, medium, device and computing device
CN107741891A
Memory-leak detection method and system
CN108182146A