[go: up one dir, main page]

CN107741891B - Destructor methods, media, devices and computing devices of objects - Google Patents

Destructor methods, media, devices and computing devices of objects Download PDF

Info

Publication number
CN107741891B
CN107741891B CN201710966413.9A CN201710966413A CN107741891B CN 107741891 B CN107741891 B CN 107741891B CN 201710966413 A CN201710966413 A CN 201710966413A CN 107741891 B CN107741891 B CN 107741891B
Authority
CN
China
Prior art keywords
class
target object
program
pointer
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201710966413.9A
Other languages
Chinese (zh)
Other versions
CN107741891A (en
Inventor
陶泽宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN201710966413.9A priority Critical patent/CN107741891B/en
Publication of CN107741891A publication Critical patent/CN107741891A/en
Application granted granted Critical
Publication of CN107741891B publication Critical patent/CN107741891B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1479Generic software techniques for error detection or fault masking
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3452Performance evaluation by statistical analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Quality & Reliability (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Evolutionary Biology (AREA)
  • Probability & Statistics with Applications (AREA)
  • Computer Hardware Design (AREA)
  • Stored Programmes (AREA)

Abstract

本发明的实施方式提供了一种对象的析构方法、介质、装置和计算设备。该对象的析构方法包括:在目标对象的生命周期结束时,对所述目标对象进行延时析构;在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。本发明实施方式的技术方案使得程序中即便出现了对生命周期已经结束的对象进行访问的问题,也能够通过将发送给该对象的方法转发至一空函数指针来保证程序的正常运行,解决了程序出现BAD ACCESS类型的崩溃而影响用户使用的问题,提高了程序运行的稳定性。

Figure 201710966413

Embodiments of the present invention provide an object destruction method, medium, apparatus and computing device. The method for destructing the object includes: when the life cycle of the target object ends, delaying the destruction of the target object; and sending the original to the The method of the target object is forwarded to a null function pointer. The technical solution of the embodiment of the present invention makes it possible to ensure the normal operation of the program by forwarding the method sent to the object to a null function pointer even if the problem of accessing the object whose life cycle has ended occurs in the program, thus solving the problem of the program. The problem of BAD ACCESS type crash affecting users' use has been improved, and the stability of program operation has been improved.

Figure 201710966413

Description

对象的析构方法、介质、装置和计算设备Destructor methods, media, devices and computing devices of objects

技术领域technical field

本发明的实施方式涉及通信及计算机技术领域,更具体地,本发明的实施方式涉及对象的析构方法、介质、装置和计算设备。The embodiments of the present invention relate to the fields of communication and computer technology, and more particularly, the embodiments of the present invention relate to methods, media, apparatuses, and computing devices for destructing objects.

背景技术Background technique

本部分旨在为权利要求书中陈述的本发明的实施方式提供背景或上下文。此处的描述不因为包括在本部分中就承认是现有技术。This section is intended to provide a background or context for the embodiments of the invention that are recited in the claims. The descriptions herein are not admitted to be prior art by inclusion in this section.

在软件开发行业,难以避免地会遇到APP(Application,应用程序)崩溃的问题,其中BAD ACCESS类型的崩溃占比很高且排查困难,BAD ACCESS类型的崩溃是程序访问了野指针导致的崩溃。In the software development industry, it is inevitable to encounter the problem of APP (Application, application) crash. Among them, BAD ACCESS type crashes account for a high proportion and are difficult to troubleshoot. BAD ACCESS type crashes are caused by programs accessing wild pointers. .

目前行业内针对BAD ACCESS类型的崩溃主要有两种处理方案:方案一是直接让APP崩溃掉,通过抓取崩溃日志分析崩溃原因,修复之后再通过发布新的APP版本来解决对应的崩溃问题;方案二是通过热更新的方式,即通过脚本文件下发修复后的代码,在运行时进行方法替换和调用脚本代码,从而达到在发布新的APP版本之前修复问题的目的。At present, there are two main solutions for BAD ACCESS type crashes in the industry: the first solution is to directly crash the APP, analyze the cause of the crash by grabbing the crash log, and then release a new APP version to solve the corresponding crash problem after repairing; The second solution is to use the hot update method, that is, to deliver the repaired code through a script file, to replace the method and call the script code at runtime, so as to achieve the purpose of repairing the problem before releasing the new APP version.

发明内容SUMMARY OF THE INVENTION

由于方案一需要通过发布新的APP版本来解决对应的崩溃问题,因此在未发布新的APP版本之前没有有效的办法来避免BAD ACCESS类型的崩溃,导致这段时间内对这种类型的崩溃无法及时处理,降低了用户体验。同时BAD ACCESS类型的崩溃由于其崩溃场景较难复现,导致排查修复难度很高,并且一旦错误修复,不仅原问题没有得到妥善的解决,还有导致其他问题产生的风险,因此针对该种类型的崩溃,崩溃场景的实时信息的获取尤为重要,但是现有的通过崩溃日志捕获实时信息的方式通常不够精确。Since the first solution needs to release a new APP version to solve the corresponding crash problem, there is no effective way to avoid the BAD ACCESS type of crash before the new APP version is released, resulting in this type of crash during this period. Timely processing reduces user experience. At the same time, the crash of the BAD ACCESS type is difficult to reproduce due to the difficulty of reproducing the crash scene, which makes it very difficult to troubleshoot and repair. The acquisition of real-time information of crash scenarios is particularly important, but the existing methods of capturing real-time information through crash logs are usually not accurate enough.

而方案二采用的热更新方式存在一定的安全性风险,并且虽然热更新技术可以达到在发布新的APP版本之前将问题修复的目的,但是其本身还是需要一个问题捕获、分析、解决及应用的过程,并不能达到实时解决问题,及时防止APP崩溃的效果。The hot update method used in the second solution has certain security risks, and although the hot update technology can achieve the purpose of repairing the problem before releasing a new APP version, it still needs a problem to capture, analyze, solve and apply. The process cannot achieve the effect of solving problems in real time and preventing APP from crashing in time.

为此,非常需要一种改进的对象析构方案,以至少解决程序出现BAD ACCESS类型的崩溃而影响用户使用的问题,提高程序运行的稳定性。For this reason, an improved object destructing scheme is very much needed, so as to at least solve the problem that the program has a BAD ACCESS type crash and affect the use of the user, and improve the stability of the program operation.

在本上下文中,本发明的实施方式期望提供一种对象的析构方法、介质、装置和计算设备。In this context, embodiments of the present invention are intended to provide an object destructuring method, medium, apparatus, and computing device.

在本发明实施方式的第一方面中,提供了一种对象的析构方法,包括:在目标对象的生命周期结束时,对所述目标对象进行延时析构;在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。In a first aspect of the embodiments of the present invention, a method for destructing an object is provided, including: when the life cycle of the target object ends, delaying the destruction of the target object; During the time period of delayed destruction, the method originally sent to the target object is forwarded to a null function pointer.

在本发明的一些实施方式中,基于前述方案,还包括:判断程序中的各个对象是否需要进行野指针防护;若判定所述程序中的任一对象需要进行野指针防护,则对所述任一对象添加标识,并将添加了所述标识的对象作为所述目标对象。In some embodiments of the present invention, based on the foregoing solution, the method further includes: judging whether each object in the program needs wild pointer protection; if it is determined that any object in the program needs wild pointer protection, then An object is marked with a mark, and the marked object is used as the target object.

在本发明的一些实施方式中,基于前述方案,根据所述各个对象的类型,判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, based on the foregoing solution, it is determined whether each object needs to be protected against wild pointers according to the type of each object.

在本发明的一些实施方式中,基于前述方案,判断程序中的各个对象是否需要进行野指针防护的步骤,包括:通过定义的新的方法替换用于创建所述各个对象的方法;在所述新的方法中判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, based on the foregoing solution, the step of judging whether each object in the program needs to be protected against wild pointers includes: replacing the method used to create the various objects with a defined new method; In the new method, it is judged whether each object needs to be protected against wild pointers.

在本发明的一些实施方式中,基于前述方案,对所述任一对象添加标识的步骤,包括:基于动态添加关联对象的函数对所述任一对象添加所述标识。In some embodiments of the present invention, based on the foregoing solution, the step of adding an identifier to the any object includes: adding the identifier to the any object based on a function of dynamically adding an associated object.

在本发明的一些实施方式中,基于前述方案,还包括:在确定对所述目标对象进行延时析构时,释放所述目标对象引用的相关属性。In some embodiments of the present invention, based on the foregoing solution, the method further includes: when it is determined to perform delayed destruction on the target object, releasing the relevant attributes referenced by the target object.

在本发明的一些实施方式中,基于前述方案,将原本发送给所述目标对象的方法转发至一空函数指针的步骤,包括:将所述目标对象的函数指针所指向的类修改为指定类,其中,所述函数指针原本指向所述目标对象的原始类;基于所述指定类拦截原本发送给所述目标对象的方法,并转发至所述空函数指针。In some embodiments of the present invention, based on the foregoing solution, the step of forwarding the method originally sent to the target object to a null function pointer includes: modifying the class pointed to by the function pointer of the target object to a specified class, Wherein, the function pointer originally points to the original class of the target object; the method originally sent to the target object is intercepted based on the specified class, and forwarded to the null function pointer.

在本发明的一些实施方式中,基于前述方案,基于所述指定类拦截原本发送给所述目标对象的方法,并转发至所述空函数指针的步骤,包括:通过所述指定类中的消息转发函数拦截原本发送给所述目标对象的方法,并返回一对象类;向所述对象类动态添加类方法,并将所述类方法的指针指向空函数。In some embodiments of the present invention, based on the foregoing solution, the step of intercepting the method originally sent to the target object based on the specified class and forwarding it to the null function pointer includes: passing a message in the specified class The forwarding function intercepts the method originally sent to the target object, and returns an object class; dynamically adds a class method to the object class, and points the pointer of the class method to an empty function.

在本发明的一些实施方式中,基于前述方案,还包括:将所述原始类的类名保存至所述目标对象中。In some embodiments of the present invention, based on the foregoing solution, the method further includes: saving the class name of the original class into the target object.

在本发明的一些实施方式中,基于前述方案,还包括:获取保存在所述目标对象中的原始类的类名;根据获取到的类名,统计程序在运行过程中出现的错误数据。In some embodiments of the present invention, based on the foregoing solution, the method further includes: obtaining the class name of the original class stored in the target object; and according to the obtained class name, counting error data that occurs during the running of the program.

在本发明的一些实施方式中,基于前述方案,还包括:判断程序是否切换至后台运行,和/或判断延时析构的目标对象的数量是否达到预定数量;在判定所述程序切换至后台运行时,和/或在判定延时析构的目标对象的数量达到所述预定数量时,调用延时析构的目标对象原有的释放内存的函数对所述目标对象进行析构。In some embodiments of the present invention, based on the foregoing solution, the method further includes: judging whether the program is switched to run in the background, and/or judging whether the number of target objects for delayed destruction reaches a predetermined number; after determining whether the program is switched to the background At runtime, and/or when it is determined that the number of target objects to be destructed in a delayed manner reaches the predetermined number, the original memory release function of the target object of deferred destructed destruction is called to destruct the target object.

在本发明实施方式的第二方面中,提供了一种介质,其上存储有程序,该程序被处理器执行时实现如上述实施方式中第一方面所述的方法。In a second aspect of an embodiment of the present invention, there is provided a medium on which a program is stored, and when the program is executed by a processor, the method as described in the first aspect of the above-mentioned embodiment is implemented.

在本发明实施方式的第三方面中,提供了一种对象的析构装置,包括:析构单元,用于在目标对象的生命周期结束时,对所述目标对象进行延时析构;处理单元,用于在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。In a third aspect of the embodiments of the present invention, an apparatus for destructing an object is provided, including: a destructing unit, configured to delay the destructing of the target object when the life cycle of the target object ends; processing The unit is configured to forward the method originally sent to the target object to a null function pointer within the time period during which the target object is destructed in a delayed manner.

在本发明的一些实施方式中,基于前述方案,还包括:第一判断单元,用于判断程序中的各个对象是否需要进行野指针防护;添加单元,用于在所述第一判断单元判定所述程序中的任一对象需要进行野指针防护时,对所述任一对象添加标识,并将添加了所述标识的对象作为所述目标对象。In some embodiments of the present invention, based on the foregoing solution, it further includes: a first judging unit for judging whether each object in the program needs to be protected against wild pointers; an adding unit for judging all objects in the first judging unit When any object in the program needs to be protected from wild pointers, an identifier is added to the any object, and the object to which the identifier is added is used as the target object.

在本发明的一些实施方式中,基于前述方案,所述第一判断单元配置为:根据所述各个对象的类型,判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, based on the foregoing solution, the first judgment unit is configured to: according to the types of the respective objects, judge whether the respective objects need to be protected from wild pointers.

在本发明的一些实施方式中,基于前述方案,所述第一判断单元配置为:通过定义的新的方法替换用于创建所述各个对象的方法;在所述新的方法中判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, based on the foregoing solution, the first judgment unit is configured to: replace the method for creating the respective objects by a defined new method; judge the respective objects in the new method Whether the object needs wild pointer protection.

在本发明的一些实施方式中,基于前述方案,所述添加单元配置为:基于动态添加关联对象的函数对所述任一对象添加所述标识。In some embodiments of the present invention, based on the foregoing solution, the adding unit is configured to: add the identifier to any of the objects based on a function of dynamically adding an associated object.

在本发明的一些实施方式中,基于前述方案,所述析构单元还用于:在确定对所述目标对象进行延时析构时,释放所述目标对象引用的相关属性。In some embodiments of the present invention, based on the foregoing solution, the destructing unit is further configured to release the relevant attributes referenced by the target object when it is determined that the target object is to be destructed in a delayed manner.

在本发明的一些实施方式中,基于前述方案,所述处理单元包括:修改单元,用于将所述目标对象的函数指针所指向的类修改为指定类,其中,所述函数指针原本指向所述目标对象的原始类;拦截单元,用于基于所述指定类拦截原本发送给所述目标对象的方法,并转发至所述空函数指针。In some embodiments of the present invention, based on the foregoing solution, the processing unit includes: a modification unit, configured to modify the class pointed to by the function pointer of the target object to a specified class, wherein the function pointer originally pointed to the The original class of the target object; the interception unit is configured to intercept the method originally sent to the target object based on the specified class, and forward it to the null function pointer.

在本发明的一些实施方式中,基于前述方案,所述拦截单元配置为:通过所述指定类中的消息转发函数拦截原本发送给所述目标对象的方法,并返回一对象类;向所述对象类动态添加类方法,并将所述类方法的指针指向空函数。In some embodiments of the present invention, based on the foregoing solution, the intercepting unit is configured to: intercept a method originally sent to the target object through a message forwarding function in the specified class, and return an object class; The object class dynamically adds a class method and points the pointer of the class method to a null function.

在本发明的一些实施方式中,基于前述方案,还包括:保存单元,用于将所述原始类的类名保存至所述目标对象中。In some embodiments of the present invention, based on the foregoing solution, the method further includes: a saving unit, configured to save the class name of the original class into the target object.

在本发明的一些实施方式中,基于前述方案,还包括:获取单元,用于获取保存在所述目标对象中的原始类的类名;统计单元,用于根据获取到的类名,统计程序在运行过程中出现的错误数据。In some embodiments of the present invention, based on the foregoing solution, it further includes: an acquisition unit, used to acquire the class name of the original class stored in the target object; a statistics unit, used to count the program according to the acquired class name Error data that occurred during operation.

在本发明的一些实施方式中,基于前述方案,还包括:第二判断单元,用于判断程序是否切换至后台运行,和/或判断延时析构的目标对象的数量是否达到预定数量;所述析构单元还用于,在所述第二判断单元判定所述程序切换至后台运行时,和/或在判定延时析构的目标对象的数量达到所述预定数量时,调用延时析构的目标对象原有的释放内存的函数对所述目标对象进行析构。In some embodiments of the present invention, based on the foregoing solution, it further includes: a second judgment unit for judging whether the program is switched to run in the background, and/or judging whether the number of target objects to be destructed by delay reaches a predetermined number; The destructuring unit is further configured to, when the second judging unit determines that the program is switched to running in the background, and/or when it is determined that the number of target objects to be destructed in a delayed manner reaches the predetermined number, call the delayed analysis unit. The original function of releasing the memory of the target object of the construction is used to destruct the target object.

在本发明实施方式的第四方面中,提供了一种计算设备,包括:处理器和存储器,所述存储器存储有可执行指令,所述处理器用于调用所述存储器存储的可执行指令执行如上述实施方式中第一方面所述的方法。In a fourth aspect of an embodiment of the present invention, a computing device is provided, including: a processor and a memory, where the memory stores executable instructions, and the processor is configured to call the executable instructions stored in the memory to execute an example such as: The method described in the first aspect of the above embodiment.

根据本发明实施方式的对象的析构方法、介质、装置和计算设备,由于BAD ACCESS类型的崩溃是程序访问了野指针导致的崩溃,因此通过在目标对象的生命周期结束时,对该目标对象进行延时析构,并在对该目标对象进行延时析构的时间段内,将原本发送给目标对象的方法转发至一空函数指针,使得程序中即便出现了对生命周期已经结束的对象进行访问的问题,也能够通过将发送给该对象的方法转发至一空函数指针来保证程序的正常运行,解决了程序出现BAD ACCESS类型的崩溃而影响用户使用的问题,提高了程序运行的稳定性。According to the object destruction method, medium, device and computing device according to the embodiments of the present invention, since the BAD ACCESS type crash is caused by the program accessing the wild pointer, the Carry out delayed destruction, and forward the method originally sent to the target object to a null function pointer within the time period of delayed destruction of the target object, so that even if there is an object whose life cycle has ended in the program The problem of access can also be ensured by forwarding the method sent to the object to a null function pointer to ensure the normal operation of the program, which solves the problem that the program has a BAD ACCESS type crash and affects the user's use, and improves the stability of the program operation.

根据本发明实施方式的对象的析构方法、介质、装置和计算设备,通过将目标对象的原始类的类名保存至目标对象中,并根据保存在目标对象中的原始类的类名来统计程序在运行过程中出现的错误数据,使得能够有效保留程序发生BAD ACCESS类型崩溃的现场信息,进而能够方便技术人员进行排查修复。According to the object destructuring method, medium, device and computing device according to the embodiments of the present invention, the class name of the original class of the target object is stored in the target object, and statistics are calculated according to the class name of the original class stored in the target object The error data that occurs in the running process of the program can effectively retain the on-site information of the BAD ACCESS type crash of the program, which can facilitate the technicians to troubleshoot and repair.

附图说明Description of drawings

通过参考附图阅读下文的详细描述,本发明示例性实施方式的上述以及其他目的、特征和优点将变得易于理解。在附图中,以示例性而非限制性的方式示出了本发明的若干实施方式,其中:The above and other objects, features and advantages of exemplary embodiments of the present invention will become readily understood by reading the following detailed description with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown by way of example and not limitation, wherein:

图1示意性示出了根据本发明的实施例的对象的析构方法的流程图;FIG. 1 schematically shows a flow chart of a method for destructing an object according to an embodiment of the present invention;

图2示意性示出了根据本发明的实施例的确定需要进行野指针防护的对象的流程图;FIG. 2 schematically shows a flowchart of determining an object that needs wild pointer protection according to an embodiment of the present invention;

图3示出了图1中所示的步骤S12的具体流程示意图;Fig. 3 shows the specific flow chart of step S12 shown in Fig. 1;

图4示意性示出了根据本发明的实施例的对需要进行野指针防护的对象实例进行处理的流程图;FIG. 4 schematically shows a flowchart of processing an object instance that needs wild pointer protection according to an embodiment of the present invention;

图5示意性示出了根据本发明的实施例的对延时析构的对象进行处理的流程图;FIG. 5 schematically shows a flow chart of processing an object destructed by delay according to an embodiment of the present invention;

图6示意性示出了根据本发明的实施例的延时析构期间的处理过程示意图;FIG. 6 schematically shows a schematic diagram of a processing procedure during a delayed destructuring period according to an embodiment of the present invention;

图7示意性示出了根据本发明的实施方式的对象的析构装置的框图。FIG. 7 schematically shows a block diagram of an object destructor according to an embodiment of the present invention.

在附图中,相同或对应的标号表示相同或对应的部分。In the drawings, the same or corresponding reference numerals denote the same or corresponding parts.

具体实施方式Detailed ways

下面将参考若干示例性实施方式来描述本发明的原理和精神。应当理解,给出这些实施方式仅仅是为了使本领域技术人员能够更好地理解进而实现本发明,而并非以任何方式限制本发明的范围。相反,提供这些实施方式是为了使本公开更加透彻和完整,并且能够将本公开的范围完整地传达给本领域的技术人员。The principles and spirit of the present invention will now be described with reference to several exemplary embodiments. It should be understood that these embodiments are only given for those skilled in the art to better understand and implement the present invention, but not to limit the scope of the present invention in any way. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

本领域技术人员知道,本发明的实施方式可以实现为一种系统、装置、设备、方法或计算机程序产品。因此,本公开可以具体实现为以下形式,即:完全的硬件、完全的软件(包括固件、驻留软件、微代码等),或者硬件和软件结合的形式。As will be appreciated by those skilled in the art, embodiments of the present invention may be implemented as a system, apparatus, device, method or computer program product. Accordingly, the present disclosure may be embodied in entirely hardware, entirely software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.

根据本发明的实施方式,提出了一种对象的析构方法、介质、装置和计算设备。According to the embodiments of the present invention, an object destruction method, medium, apparatus and computing device are provided.

在本文中,需要理解的是,所涉及的术语“程序”、“应用程序”和“应用”是指安装在手机等智能设备上的程序,简称为APP,一般需要与服务端互相配合运行。常见的应用主要分两类:一类是预装的系统应用,比如短信、照片、备忘录等;另一类是第三方应用,比如资讯类的网易新闻、购物类的淘宝、社交类的微信等等。In this article, it should be understood that the terms "program", "application" and "application" refer to programs installed on smart devices such as mobile phones, referred to as APPs, which generally need to cooperate with the server to run. Common applications are mainly divided into two categories: one is pre-installed system applications, such as text messages, photos, memos, etc.; the other is third-party applications, such as NetEase News for information, Taobao for shopping, WeChat for social networking, etc. Wait.

术语“程序崩溃”是指APP在运行时非正常的突然退出的现象,程序崩溃会导致用户正在进行的操作全部被中断。The term "program crash" refers to the phenomenon that the APP exits abnormally and suddenly during operation, and the program crash will cause all the ongoing operations of the user to be interrupted.

术语“BAD ACCESS”是指程序访问了野指针导致的崩溃,比如对一个已经释放的对象执行release(释放),访问已经释放对象的成员变量或者向其发消息等。The term "BAD ACCESS" refers to a crash caused by a program accessing a wild pointer, such as performing a release on a released object, accessing a member variable of a released object, or sending a message to it.

术语“野指针”表示指向一个已删除的对象或未申请访问受限内存区域的指针。The term "wild pointer" means a pointer to a deleted object or an unclaimed access restricted memory area.

术语“析构”是指在撤消对象时进行的一些清理任务,如释放分配给对象的内存空间等。The term "destruction" refers to some cleanup tasks performed when an object is undone, such as freeing memory space allocated to the object, etc.

此外,附图中的任何元素数量均用于示例而非限制,以及任何命名都仅用于区分,而不具有任何限制含义。Furthermore, any number of elements in the drawings is for illustration and not limitation, and any designation is for distinction only and does not have any limiting meaning.

下面参考本发明的若干代表性实施方式,详细阐释本发明的原理和精神。The principles and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention.

发明概述SUMMARY OF THE INVENTION

本发明人发现,目前发布新的APP版本来解决BAD ACCESS类型崩溃的方案在未发布新的APP版本之前不能避免BAD ACCESS类型的崩溃,导致这段时间内对这种类型的崩溃无法及时处理,降低了用户体验。而采用热更新的方式存在一定的安全性风险,并且虽然热更新技术可以达到在发布新的APP版本之前将问题修复的目的,但是其本身还是需要一个问题捕获、分析、解决及应用的过程,并不能达到实时解决问题,及时防止APP崩溃的效果。The inventors found that the current solution for releasing a new APP version to solve the BAD ACCESS type crash cannot avoid the BAD ACCESS type crash before the new APP version is released, resulting in that this type of crash cannot be dealt with in time during this period, Degraded user experience. The hot update method has certain security risks, and although the hot update technology can achieve the purpose of fixing problems before releasing a new APP version, it still needs a process of problem capture, analysis, resolution and application. It cannot solve the problem in real time and prevent the APP from crashing in time.

因此,本发明的实施方式提供了一种改进的对象析构方法、介质、装置和计算设备,使得即便程序中出现了对生命周期已经结束的对象进行访问的问题,也能够通过将发送给该对象的方法转发至一空函数指针来保证程序的正常运行,解决了程序出现BADACCESS类型的崩溃而影响用户使用的问题,提高了程序运行的稳定性。Therefore, the embodiments of the present invention provide an improved object destructuring method, medium, apparatus and computing device, so that even if there is a problem of accessing an object whose life cycle has ended in a program, it can be sent to the The method of the object is forwarded to a null function pointer to ensure the normal operation of the program, which solves the problem that the program crashes of the BADACCESS type and affects the user's use, and improves the stability of the program operation.

在介绍了本发明的基本原理之后,下面具体介绍本发明的各种非限制性实施方式。Having introduced the basic principles of the present invention, various non-limiting embodiments of the present invention are described in detail below.

应用场景总览Application Scenario Overview

需要注意的是,下述应用场景仅是为了便于理解本发明的精神和原理而示出,本发明的实施方式在此方面不受任何限制。相反,本发明的实施方式可以应用于适用的任何场景。It should be noted that the following application scenarios are only shown for easy understanding of the spirit and principle of the present invention, and the embodiments of the present invention are not limited in this respect. Rather, embodiments of the present invention can be applied to any scenario where applicable.

场景一:当程序中的某一对象的生命周期结束时,对该对象进行延时析构,并且在延时析构的时间段内,若有发送给该对象的方法,则将该方法转发至一空函数指针,进而能够避免程序中访问野指针而出现BAD ACCESS类型崩溃的问题。Scenario 1: When the life cycle of an object in the program ends, the object is deferred and destructed, and if there is a method sent to the object within the time period of deferred destruction, the method is forwarded To a null function pointer, it can avoid the problem of BAD ACCESS type crash caused by accessing wild pointers in the program.

场景二:对于延时析构的目标对象,可以将该目标对象的原始类的类名保存至该目标对象中,并根据保存在该目标对象中的原始类的类名来统计程序在运行过程中出现的错误数据,这样能够有效保留程序发生BAD ACCESS类型崩溃的现场信息,进而能够方便技术人员进行排查修复。Scenario 2: For the target object of delayed destruction, the class name of the original class of the target object can be saved to the target object, and the running process of the program can be counted according to the class name of the original class saved in the target object. In this way, the on-site information of the BAD ACCESS type crash of the program can be effectively preserved, and then it is convenient for the technicians to troubleshoot and repair.

示例性方法Exemplary method

下面结合上述的应用场景,参考图1至图6来描述根据本发明示例性实施方式的对象的析构方法。The following describes an object destructuring method according to an exemplary embodiment of the present invention with reference to FIG. 1 to FIG. 6 in conjunction with the above application scenarios.

图1示意性示出了根据本发明的实施例的对象的析构方法的流程图。FIG. 1 schematically shows a flow chart of a method for destructing an object according to an embodiment of the present invention.

参照图1所示,根据本发明的实施例的对象的析构方法,包括:Referring to FIG. 1 , the method for destructing an object according to an embodiment of the present invention includes:

步骤S10,在目标对象的生命周期结束时,对所述目标对象进行延时析构。Step S10, when the life cycle of the target object ends, perform delayed destruction on the target object.

需要说明的是,在本发明的实施方式中,对象的生命周期结束可以是对象所在的函数已调用完毕。It should be noted that, in the embodiment of the present invention, the end of the life cycle of the object may mean that the function where the object is located has been called.

此外,在本发明的实施方式中,当确定对目标对象进行延时析构时,可以释放该目标对象引用的相关属性。In addition, in the embodiment of the present invention, when it is determined that the target object is to be destructed in a delayed manner, the related properties referenced by the target object may be released.

在本发明的实施方式中,由于程序中存在很多系统类,比如ISO系统中的NSString、UIView等创建、释放非常频繁,这些实例发生野指针的概率非常低,为了提高效率,无需对所有对象都进行野指针防护。因此,本发明的实施方式提供了如图2所示的确定需要进行野指针防护的目标对象的方案,具体包括:In the embodiment of the present invention, since there are many system classes in the program, such as NSString, UIView, etc. in the ISO system are created and released very frequently, the probability of wild pointer occurrence in these instances is very low. Perform wild pointer protection. Therefore, the embodiments of the present invention provide a solution for determining a target object that needs wild pointer protection as shown in FIG. 2, which specifically includes:

步骤S20,判断程序中的各个对象是否需要进行野指针防护。Step S20, it is judged whether each object in the program needs to be protected against wild pointers.

在本发明的实施方式中,可以根据程序中各个对象的类型,判断各个对象是否需要进行野指针防护。比如对于系统类的某些对象,无需进行野指针防护,而对于自定义类的某些对象,则可以进行野指针防护。In the embodiment of the present invention, whether each object needs to be protected against wild pointers can be determined according to the type of each object in the program. For example, for some objects of system classes, wild pointer protection is not required, while for some objects of custom classes, wild pointer protection can be performed.

在本发明的示例性实施方式中,步骤S20可以包括:通过定义的新的方法替换用于创建所述各个对象的方法,在所述新的方法中判断所述各个对象是否需要进行野指针防护。In an exemplary embodiment of the present invention, step S20 may include: replacing the method for creating the respective objects with a defined new method, and judging in the new method whether wild pointer protection is required for the respective objects .

比如对于IOS系统,可以利用method swizzling替换NSObject(IOS系统中的类)的allocWithZone(IOS系统中创建类实例的方法)方法,然后在新的方法中判断对象是否需要进行野指针防护。For example, for the IOS system, you can use method swizzling to replace the allocWithZone (method of creating a class instance in the IOS system) method of NSObject (a class in the IOS system), and then determine whether the object needs wild pointer protection in the new method.

步骤S22,若判定程序中的任一对象需要进行野指针防护,则对所述任一对象添加标识,并将添加了所述标识的对象作为所述目标对象。Step S22, if it is determined that any object in the program needs to be protected against wild pointers, add an identifier to the any object, and use the object to which the identifier is added as the target object.

在本发明的示例性实施方式中,步骤S22中对任一对象添加标识的步骤可以包括:基于动态添加关联对象的函数对所述任一对象添加所述标识。In an exemplary embodiment of the present invention, the step of adding an identifier to any object in step S22 may include: adding the identifier to the any object based on a function of dynamically adding an associated object.

比如对于IOS系统,可以通过objc_setAssociatedObject(IOS系统中动态添加关联对象的函数)关联对象为该需要进行野指针防护的对象设置标识,被标识的对象后续会进入后续的防护流程。For example, for the IOS system, you can use the objc_setAssociatedObject (the function for dynamically adding associated objects in the IOS system) to set an identifier for the object that needs wild pointer protection, and the identified object will enter the subsequent protection process.

继续参照图1,所述的对象的析构方法还包括:Continuing to refer to FIG. 1 , the destructuring method of the object further includes:

步骤S12,在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。Step S12 , forward the method originally sent to the target object to a null function pointer within the time period during which the target object is destructed in a delayed manner.

在本发明的实施方式中,参照图3所示,步骤S12包括如下步骤:In an embodiment of the present invention, referring to FIG. 3 , step S12 includes the following steps:

步骤S121,将目标对象的函数指针所指向的类修改为指定类,其中,所述函数指针原本指向所述目标对象的原始类。Step S121: Modify the class pointed to by the function pointer of the target object to a specified class, wherein the function pointer originally pointed to the original class of the target object.

比如对于IOS系统,可以将目标对象原本指向其原始类的函数指针(即isa指针)修改为指向自定义的类,该自定义的类是事先定义好的用于处理延时析构对象的类。For example, for the IOS system, the function pointer (that is, the isa pointer) that the target object originally points to its original class can be modified to point to a custom class, which is a pre-defined class for processing delayed destructor objects .

步骤S122,基于所述指定类拦截原本发送给所述目标对象的方法,并转发至所述空函数指针。Step S122, intercepting the method originally sent to the target object based on the specified class, and forwarding it to the null function pointer.

在本发明的示例性实施方式中,步骤S122包括:通过指定类中的消息转发函数拦截原本发送给所述目标对象的方法,并返回一对象类;向所述对象类动态添加类方法,并将所述类方法的指针指向空函数。In an exemplary embodiment of the present invention, step S122 includes: intercepting a method originally sent to the target object through a message forwarding function in a specified class, and returning an object class; dynamically adding a class method to the object class, and Point the pointer of the class method to a null function.

比如对于IOS系统,可以通过自定义的类拦截原本发送给目标对象的方法,并返回一对象类(如stubProxy),然后向该对象类动态添加selector(即类方法),使selector的imp指针指向一个空函数,该空函数返回0。For example, for the IOS system, you can intercept the method originally sent to the target object through a custom class, and return an object class (such as stubProxy), and then dynamically add a selector (ie, a class method) to the object class, so that the imp pointer of the selector points to An empty function that returns 0.

需要说明的是,对于生命周期已经结束的对象,本发明的实施方式是对其进行延时析构,但是最终还是需要对这些对象进行析构,基于此,本发明提出了如下的结束延时析构的方案:It should be noted that, for the objects whose life cycle has ended, the implementation of the present invention is to delay the destruction of the objects, but these objects still need to be destroyed in the end. Based on this, the present invention proposes the following end delay Destruction scheme:

在本发明的一些实施方式中,判断程序是否切换至后台运行,和/或判断延时析构的目标对象的数量是否达到预定数量;在判定所述程序切换至后台运行时,和/或在判定延时析构的目标对象的数量达到所述预定数量时,调用延时析构的目标对象原有的释放内存的函数对所述目标对象进行析构。In some embodiments of the present invention, it is judged whether the program is switched to run in the background, and/or whether the number of target objects to be destructed in a delayed manner reaches a predetermined number; when it is judged that the program is switched to run in the background, and/or when When it is determined that the number of target objects to be destructed in a delayed manner reaches the predetermined number, the original memory release function of the target object of deferred destructed destruction is called to destruct the target object.

基于前述的方案,本发明的实施方式还提供了如下方案:将所述原始类的类名保存至所述目标对象中。获取保存在所述目标对象中的原始类的类名;根据获取到的类名,统计程序在运行过程中出现的错误数据。Based on the foregoing solution, an embodiment of the present invention further provides the following solution: saving the class name of the original class into the target object. Acquire the class name of the original class stored in the target object; according to the obtained class name, count the error data that occurs during the running of the program.

在本发明的实施方式中,通过将目标对象的原始类的类名保存至目标对象中,并根据保存在目标对象中的原始类的类名来统计程序在运行过程中出现的错误数据,使得能够有效保留程序发生BAD ACCESS类型崩溃的现场信息,进而能够方便技术人员进行排查修复。In the embodiment of the present invention, by saving the class name of the original class of the target object into the target object, and according to the class name of the original class saved in the target object, the error data that occurs during the running of the program is counted, so that It can effectively retain the on-site information of the BAD ACCESS type crash of the program, which can facilitate the technicians to troubleshoot and repair.

以下以IOS系统为例,对本发明实施方式的对象的析构方法进行详细阐述,主要包含以下4个过程:Taking the IOS system as an example below, the method for destructing an object according to an embodiment of the present invention will be described in detail, which mainly includes the following four processes:

1、参照图4所示,包括如下步骤:1. Referring to Figure 4, it includes the following steps:

步骤S401,利用method swizzling替换NSObject中原有的allocWithZone方法。Step S401, using method swizzling to replace the original allocWithZone method in NSObject.

步骤S402,在新的方法中判断该类型对象是否需要进行野指针防护,若是,则执行步骤S403;否则,执行步骤S404。Step S402, in the new method, it is judged whether the object of this type needs to be protected against wild pointers, and if so, step S403 is performed; otherwise, step S404 is performed.

步骤S403,通过objc_setAssociatedObject为该对象实例设置flag标记,被标记的对象后续会进入防护流程。In step S403, a flag is set for the object instance through objc_setAssociatedObject, and the marked object will enter the protection process later.

步骤S404,调用原有的allocWithZone方法进行处理。Step S404, calling the original allocWithZone method for processing.

图4所示的流程具体是通过hook原有的allocWithZone方法来对需要进行野指针防护的对象实例添加标记,以便后续流程进行识别。The process shown in Figure 4 is to add tags to the object instances that need wild pointer protection by hooking the original allocWithZone method, so that the subsequent process can identify them.

2、参照图5所示,包含如下步骤:2. Referring to Figure 5, it includes the following steps:

步骤S501,对于生命周期已经结束的对象,利用method swizzling替换NSObject中原有的dealloc方法。Step S501, for the object whose life cycle has ended, use method swizzling to replace the original dealloc method in NSObject.

步骤S502,判断对象实例是否有flag标记,若有,则执行步骤S504;否则,执行步骤S503。Step S502, it is judged whether the object instance has a flag, and if so, step S504 is performed; otherwise, step S503 is performed.

步骤S503,调用原有的dealloc方法释放该对象实例。即对于无需进行野指针防护的对象实例,则直接通过原有的dealloc方法释放该对象实例即可。Step S503, calling the original dealloc method to release the object instance. That is, for an object instance that does not need wild pointer protection, the object instance can be released directly through the original dealloc method.

步骤S504,对有flag标记的对象实例调用objc_destructInstance方法释放该实例引用的相关属性。Step S504, calling the objc_destructInstance method on the object instance marked with the flag to release the relevant attributes referenced by the instance.

步骤S505,将该对象实例的isa修改为HTZombieObject类。HTZombieObject类是事先定义好的一个专门用来处理延时析构对象的类,可以将所以发送给该类对象的方法和消息全部转发到一个空函数指针上。Step S505, modify the isa of the object instance to the HTZombieObject class. The HTZombieObject class is a pre-defined class specially used to deal with delayed destructor objects. It can forward all methods and messages sent to this class of objects to a null function pointer.

步骤S506,通过objc_setAssociatedObject将原始类名保存在该实例中,以供后续错误统计使用。In step S506, the original class name is saved in the instance through objc_setAssociatedObject for use in subsequent error statistics.

步骤S507,判断延时析构的对象是否达到上限,若是,则执行步骤S508;否则,直接执行步骤S509。In step S507, it is judged whether the object to be destructed by delay reaches the upper limit, and if so, step S508 is performed; otherwise, step S509 is directly performed.

步骤S508,调用ht_freeSomeMemory释放缓存,以便于将该对象实例加入缓存中。Step S508, calling ht_freeSomeMemory to release the cache, so as to add the object instance to the cache.

步骤S509,将该对象实例加入缓存中。Step S509, adding the object instance to the cache.

3、参照图6所示,包括以下步骤:3. Referring to Figure 6, it includes the following steps:

步骤S601,重写HTZombieObject中的forwardingTargetForSelector方法,以通过消息转发机制forwardingTargetForSelector拦截所有传给HTZombieObject的消息。Step S601, rewrite the forwardingTargetForSelector method in the HTZombieObject to intercept all messages transmitted to the HTZombieObject through the message forwarding mechanism forwardingTargetForSelector.

步骤S602,创建桩类stubProxy。Step S602, creating a stub class stubProxy.

步骤S603,为桩类动态添加对应的selector,selector的imp指向空函数,该空函数返回0。即通过一个返回为空的函数来达到程序不崩溃的目的。Step S603, dynamically add a corresponding selector to the stub class, the imp of the selector points to an empty function, and the empty function returns 0. That is, the purpose of the program not to crash is achieved through a function that returns empty.

步骤S604,通过objc_getAssociatedObject获取之前保存的该对象实例的原始类名,统计错误数据。In step S604, the original class name of the object instance saved before is obtained through objc_getAssociatedObject, and error data is counted.

步骤S605,return stubProxy将消息转移到该桩类对象上。进而当forwardingTargetForSelector拦截到传递给HTZombieObject的消息后,可以将该消息转移到该桩类对象上,由于该桩类对象的类方法selector的imp指向空函数,因此最后会返回0,实现了即便访问了生命周期已经结束的对象实例,也能够确保程序不崩溃的目的。Step S605, return stubProxy to transfer the message to the stub class object. Furthermore, when forwardingTargetForSelector intercepts the message passed to HTZombieObject, it can transfer the message to the stub class object. Since the imp of the class method selector of the stub class object points to an empty function, it will return 0 in the end, realizing that even if it is accessed The object instance whose life cycle has ended can also ensure that the program does not crash.

4、当程序退到后台或者延时析构的对象实例达到上限时,则调用析构对象原有的dealloc方法释放所有延时析构的对象实例。4. When the program returns to the background or the object instance of the delayed destructor reaches the upper limit, the original dealloc method of the destructor object is called to release all the object instances of the delayed destructor.

需要说明的是:图4至图6以IOS系统为例对本发明实施例的析构方法进行了详细阐述,本领域技术人员需要理解的是,对于其它的操作系统,同样可以适用于本发明实施例的析构方法。It should be noted that: FIGS. 4 to 6 take the IOS system as an example to describe the destructuring method of the embodiment of the present invention in detail. It should be understood by those skilled in the art that other operating systems are also applicable to the implementation of the present invention. Example destructor method.

示例性介质Exemplary Media

在介绍了本发明示例性实施方式的方法之后,接下来,对本发明示例性实施方式的介质进行说明。After introducing the method of the exemplary embodiment of the present invention, next, the medium of the exemplary embodiment of the present invention is described.

在一些可能的实施方式中,本发明的各个方面还可以实现为一种介质,其上存储有程序代码,当所述程序代码被设备的处理器执行时用于实现本说明书上述“示例性方法”部分中描述的根据本发明各种示例性实施方式的对象的析构方法中的步骤。In some possible implementations, various aspects of the present invention can also be implemented as a medium having stored thereon program code for implementing the "exemplary method" described above in this specification when the program code is executed by a processor of a device. The steps in the destructor method of an object according to various exemplary embodiments of the present invention described in the "" section.

具体地,所述设备的处理器执行所述程序代码时用于实现如下步骤:在目标对象的生命周期结束时,对所述目标对象进行延时析构;在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。Specifically, when the processor of the device executes the program code, it is configured to implement the following steps: when the life cycle of the target object ends, delay the destruction of the target object; when the target object is delayed During the time period of destruction, the method originally sent to the target object is forwarded to a null function pointer.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时还用于实现如下步骤:判断程序中的各个对象是否需要进行野指针防护;若判定所述程序中的任一对象需要进行野指针防护,则对所述任一对象添加标识,并将添加了所述标识的对象作为所述目标对象。In some embodiments of the present invention, when the processor of the device executes the program code, it is further configured to implement the following steps: judging whether each object in the program needs wild pointer protection; If the object needs to be protected from wild pointers, an identifier is added to any of the objects, and the object to which the identifier is added is used as the target object.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时还用于实现如下步骤:根据所述各个对象的类型,判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, when the processor of the device executes the program code, it is further configured to implement the following step: according to the type of each object, determine whether each object needs to be protected against wild pointers.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时用于实现如下步骤:通过定义的新的方法替换用于创建所述各个对象的方法;在所述新的方法中判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, when the processor of the device executes the program code, it is configured to implement the following steps: replace the method used to create the various objects by defining a new method; Determine whether the objects need wild pointer protection.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时用于实现如下步骤:基于动态添加关联对象的函数对所述任一对象添加所述标识。In some embodiments of the present invention, when the processor of the device executes the program code, it is configured to implement the following step: adding the identifier to any object based on a function of dynamically adding an associated object.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时还用于实现如下步骤:在确定对所述目标对象进行延时析构时,释放所述目标对象引用的相关属性。In some embodiments of the present invention, when the processor of the device executes the program code, it is further configured to implement the following step: when it is determined that the target object is to be destructed in a delayed manner, release the related reference of the target object. Attributes.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时用于实现如下步骤:将所述目标对象的函数指针所指向的类修改为指定类,其中,所述函数指针原本指向所述目标对象的原始类;基于所述指定类拦截原本发送给所述目标对象的方法,并转发至所述空函数指针。In some embodiments of the present invention, when the processor of the device executes the program code, it is configured to implement the following steps: modify the class pointed to by the function pointer of the target object to a specified class, wherein the function pointer Originally pointing to the original class of the target object; intercepting the method originally sent to the target object based on the specified class, and forwarding to the null function pointer.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时用于实现如下步骤:通过所述指定类中的消息转发函数拦截原本发送给所述目标对象的方法,并返回一对象类;向所述对象类动态添加类方法,并将所述类方法的指针指向空函数。In some embodiments of the present invention, when the processor of the device executes the program code, it is configured to implement the following steps: intercept the method originally sent to the target object through the message forwarding function in the specified class, and return An object class; dynamically add a class method to the object class, and point the pointer of the class method to a null function.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时用于实现如下步骤:将所述原始类的类名保存至所述目标对象中。In some embodiments of the present invention, when the processor of the device executes the program code, it is configured to implement the following step: saving the class name of the original class into the target object.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时还用于实现如下步骤:获取保存在所述目标对象中的原始类的类名;根据获取到的类名,统计程序在运行过程中出现的错误数据。In some embodiments of the present invention, the processor of the device is further configured to implement the following steps when executing the program code: obtaining the class name of the original class stored in the target object; according to the obtained class name, Error data that occurs during the operation of the statistical program.

在本发明的一些实施方式中,所述设备的处理器执行所述程序代码时还用于实现如下步骤:判断程序是否切换至后台运行,和/或判断延时析构的目标对象的数量是否达到预定数量;在判定所述程序切换至后台运行时,和/或在判定延时析构的目标对象的数量达到所述预定数量时,调用延时析构的目标对象原有的释放内存的函数对所述目标对象进行析构。In some embodiments of the present invention, when the processor of the device executes the program code, it is further configured to implement the following steps: judging whether the program is switched to run in the background, and/or judging whether the number of target objects to be destructed in a delayed manner is A predetermined number is reached; when it is determined that the program is switched to run in the background, and/or when it is determined that the number of the target objects of the delayed destruction reaches the predetermined number, the original free memory of the target object of the delayed destruction is called. The function destructs the target object.

需要说明的是:上述的介质可以是可读信号介质或者可读存储介质。可读存储介质例如可以是但不限于:电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。可读存储介质的更具体的例子(非穷举的列表)包括:具有一个或多个导线的电连接、便携式盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。It should be noted that: the above-mentioned medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: electrical connections with one or more wires, portable disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了可读程序代码。这种传播的数据信号可以采用多种形式,包括但不限于:电磁信号、光信号或上述的任意合适的组合。可读信号介质还可以是可读存储介质以外的任何可读介质,该可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。A readable signal medium may include a propagated data signal in baseband or as part of a carrier wave, carrying readable program code therein. Such propagated data signals may take a variety of forms including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium can also be any readable medium other than a readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.

可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、有线、光缆、RF等,或者上述的任意合适的组合。Program code embodied on a readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

可以以一种或多种程序设计语言的任意组合来编写用于执行本发明操作的程序代码,所述程序设计语言包括面向对象的程序设计语言—诸如Java、C++等,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算设备上执行、部分在用户计算设备上部分在远程计算设备上执行、或者完全在远程计算设备或服务器上执行。在涉及远程计算设备的情形中,远程计算设备可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)—连接到用户计算设备,或者,可以连接到外部计算设备(例如利用因特网服务提供商来通过因特网连接)。Program code for carrying out operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages—such as Java, C++, etc., as well as conventional procedural Programming Language - such as the "C" language or similar programming language. The program code may execute entirely on the user computing device, partly on the user computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (eg, using an Internet service) provider to connect via the Internet).

示例性装置Exemplary device

在介绍了本发明示例性实施方式的介质之后,接下来,参考图7对本发明示例性实施方式的对象的析构装置进行说明。After introducing the medium of the exemplary embodiment of the present invention, next, the destructor of the object of the exemplary embodiment of the present invention will be described with reference to FIG. 7 .

图7示意性示出了根据本发明的实施方式的对象的析构装置的框图。FIG. 7 schematically shows a block diagram of an object destructor according to an embodiment of the present invention.

参照图7所示,根据本发明的实施方式的对象的析构装置700,包括:析构单元702和处理单元704。Referring to FIG. 7 , an object destructing apparatus 700 according to an embodiment of the present invention includes a destructing unit 702 and a processing unit 704 .

具体地,析构单元702用于在目标对象的生命周期结束时,对所述目标对象进行延时析构;处理单元704用于在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。Specifically, the destructing unit 702 is configured to perform delayed destruction of the target object when the life cycle of the target object ends; the processing unit 704 is configured to perform delayed destruction of the target object within the time period of the delayed destruction of the target object, Forward the method originally sent to the target object to a null function pointer.

在本发明的一些实施方式中,基于前述方案,还包括:第一判断单元706,用于判断程序中的各个对象是否需要进行野指针防护;添加单元708,用于在所述第一判断单元706判定所述程序中的任一对象需要进行野指针防护时,对所述任一对象添加标识,并将添加了所述标识的对象作为所述目标对象。In some embodiments of the present invention, based on the foregoing solution, it further includes: a first judging unit 706 for judging whether each object in the program needs to be protected from wild pointers; an adding unit 708 for judging in the first judging unit 706 When it is determined that any object in the program needs to be protected from wild pointers, add an identifier to the any object, and use the object to which the identifier is added as the target object.

在本发明的一些实施方式中,基于前述方案,所述第一判断单元706配置为:根据所述各个对象的类型,判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, based on the foregoing solution, the first judgment unit 706 is configured to: according to the type of each object, determine whether each object needs to be protected from wild pointers.

在本发明的一些实施方式中,基于前述方案,所述第一判断单元706配置为:通过定义的新的方法替换用于创建所述各个对象的方法;在所述新的方法中判断所述各个对象是否需要进行野指针防护。In some embodiments of the present invention, based on the foregoing solution, the first judgment unit 706 is configured to: replace the method for creating the respective objects by a defined new method; judge the Whether each object needs wild pointer protection.

在本发明的一些实施方式中,基于前述方案,所述添加单元708配置为:基于动态添加关联对象的函数对所述任一对象添加所述标识。In some embodiments of the present invention, based on the foregoing solution, the adding unit 708 is configured to: add the identifier to the any object based on a function of dynamically adding an associated object.

在本发明的一些实施方式中,基于前述方案,所述析构单元702还用于:在确定对所述目标对象进行延时析构时,释放所述目标对象引用的相关属性。In some embodiments of the present invention, based on the foregoing solution, the destructing unit 702 is further configured to release the relevant attributes referenced by the target object when it is determined that the target object is to be destructed in a delayed manner.

在本发明的一些实施方式中,基于前述方案,所述处理单元704包括:修改单元7042,用于将所述目标对象的函数指针所指向的类修改为指定类,其中,所述函数指针原本指向所述目标对象的原始类;拦截单元7044,用于基于所述指定类拦截原本发送给所述目标对象的方法,并转发至所述空函数指针。In some embodiments of the present invention, based on the foregoing solution, the processing unit 704 includes: a modification unit 7042, configured to modify the class pointed to by the function pointer of the target object to a specified class, wherein the function pointer originally Pointing to the original class of the target object; the intercepting unit 7044 is configured to intercept the method originally sent to the target object based on the specified class, and forward it to the null function pointer.

在本发明的一些实施方式中,基于前述方案,所述拦截单元7044配置为:通过所述指定类中的消息转发函数拦截原本发送给所述目标对象的方法,并返回一对象类;向所述对象类动态添加类方法,并将所述类方法的指针指向空函数。In some embodiments of the present invention, based on the foregoing solution, the intercepting unit 7044 is configured to: intercept the method originally sent to the target object through the message forwarding function in the specified class, and return an object class; The class method is dynamically added to the object class, and the pointer of the class method points to a null function.

在本发明的一些实施方式中,基于前述方案,还包括:保存单元710,用于将所述原始类的类名保存至所述目标对象中。In some embodiments of the present invention, based on the foregoing solution, the method further includes: a saving unit 710, configured to save the class name of the original class into the target object.

在本发明的一些实施方式中,基于前述方案,还包括:获取单元712,用于获取保存在所述目标对象中的原始类的类名;统计单元,用于根据获取到的类名,统计程序在运行过程中出现的错误数据。In some embodiments of the present invention, based on the foregoing solution, the following further includes: an obtaining unit 712, configured to obtain the class name of the original class stored in the target object; a statistics unit, configured to collect statistics according to the obtained class name Error data that occurs while the program is running.

在本发明的一些实施方式中,基于前述方案,还包括:第二判断单元714,用于判断程序是否切换至后台运行,和/或判断延时析构的目标对象的数量是否达到预定数量;所述析构单元702还用于,在所述第二判断单元判定所述程序切换至后台运行时,和/或在判定延时析构的目标对象的数量达到所述预定数量时,调用延时析构的目标对象原有的释放内存的函数对所述目标对象进行析构。In some embodiments of the present invention, based on the foregoing solution, it further includes: a second judgment unit 714 for judging whether the program is switched to run in the background, and/or judging whether the number of target objects for delayed destructuring reaches a predetermined number; The destructing unit 702 is further configured to, when the second judging unit determines that the program is switched to run in the background, and/or when it is determined that the number of target objects to be destructed in a delayed manner reaches the predetermined number, call the delay. The original function of releasing memory of the target object to be destructed at the time of destructing destructs the target object.

示例性计算设备Exemplary Computing Device

在介绍了本发明示例性实施方式的方法、介质和装置之后,接下来,介绍根据本发明的另一示例性实施方式的计算设备。After introducing the method, medium and apparatus of the exemplary embodiments of the present invention, next, a computing device according to another exemplary embodiment of the present invention is introduced.

所属技术领域的技术人员能够理解,本发明的各个方面可以实现为系统、方法或程序产品。因此,本发明的各个方面可以具体实现为以下形式,即:完全的硬件实施方式、完全的软件实施方式(包括固件、微代码等),或硬件和软件方面结合的实施方式,这里可以统称为“电路”、“模块”或“系统”。As will be appreciated by one skilled in the art, various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention can be embodied in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software aspects, which may be collectively referred to herein as implementations "circuit", "module" or "system".

在一些可能的实施方式中,根据本发明实施方式的计算设备可以至少包括至少一个处理器、以及至少一个存储器。其中,所述存储器存储有程序代码,当所述程序代码被所述处理器执行时,使得所述处理器执行本说明书上述“示例性方法”部分中描述的根据本发明各种示例性实施方式的对象的析构方法中的步骤。例如,所述处理器可以执行如图1中所示的步骤S10,在目标对象的生命周期结束时,对所述目标对象进行延时析构;步骤S12,在对所述目标对象进行延时析构的时间段内,将原本发送给所述目标对象的方法转发至一空函数指针。又如,所述处理器也可以执行如图2至图6中所示的步骤。In some possible implementations, a computing device according to an embodiment of the present invention may include at least one processor, and at least one memory. Wherein, the memory stores program codes that, when executed by the processor, cause the processor to perform various exemplary embodiments according to the present invention described in the above-mentioned "Exemplary Methods" section of this specification The steps in the destructor of the object. For example, the processor may execute step S10 as shown in FIG. 1 , when the life cycle of the target object ends, delay the destruction of the target object; in step S12 , delay the target object During the time period of destruction, the method originally sent to the target object is forwarded to a null function pointer. As another example, the processor may also perform the steps shown in FIGS. 2 to 6 .

应当注意,尽管在上文详细描述中提及了对象的析构装置的若干单元或子单元,但是这种划分仅仅是示例性的,并非是强制性的。实际上,根据本发明的实施方式,上文描述的两个或更多模块或单元的特征和功能可以在一个模块或单元中具体化。反之,上文描述的一个模块或单元的特征和功能可以进一步划分为由多个模块或单元来具体化。It should be noted that although several units or sub-units of the object's destructor are mentioned in the above detailed description, this division is merely exemplary and not mandatory. Indeed, according to embodiments of the present invention, the features and functions of two or more modules or units described above may be embodied in one module or unit. Conversely, the features and functions of one module or unit described above may be further divided into multiple modules or units to be embodied.

此外,尽管在附图中以特定顺序描述了本发明方法的操作,但是,这并非要求或者暗示必须按照该特定顺序来执行这些操作,或是必须执行全部所示的操作才能实现期望的结果。附加地或备选地,可以省略某些步骤,将多个步骤合并为一个步骤执行,和/或将一个步骤分解为多个步骤执行。Furthermore, although the operations of the methods of the present invention are depicted in the figures in a particular order, this does not require or imply that the operations must be performed in the particular order, or that all illustrated operations must be performed to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined to be performed as one step, and/or one step may be decomposed into multiple steps to be performed.

虽然已经参考若干具体实施方式描述了本发明的精神和原理,但是应该理解,本发明并不限于所公开的具体实施方式,对各方面的划分也不意味着这些方面中的特征不能组合以进行受益,这种划分仅是为了表述的方便。本发明旨在涵盖所附权利要求的精神和范围内所包括的各种修改和等同布置。While the spirit and principles of the present invention have been described with reference to a number of specific embodiments, it should be understood that the invention is not limited to the specific embodiments disclosed, nor does the division of aspects imply that features of these aspects cannot be combined to perform Benefit, this division is only for convenience of presentation. The invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims (18)

1. A method of deconstruction of an object, comprising:
when the life cycle of a target object is finished, carrying out time delay analysis on the target object;
within the time period of performing delay analysis on the target object, forwarding the method originally sent to the target object to a null function pointer;
judging whether the program is switched to a background to run or not and judging whether the number of the target objects subjected to time delay analysis reaches a preset number or not;
when the program is judged to be switched to the background operation and the quantity of the target objects subjected to the delayed destruct is judged to reach the preset quantity, the original function of releasing the memory of the target objects subjected to the delayed destruct is called to destruct the target objects;
the step of forwarding the method originally sent to the target object to a null function pointer includes:
modifying the class pointed by the function pointer of the target object into a designated class, and storing the class name of the original class of the target object into the target object; wherein the function pointer originally points to an original class of the target object;
and intercepting a method originally sent to the target object based on the specified class, and forwarding the method to the null function pointer.
2. The method of claim 1, further comprising:
judging whether each object in the program needs to perform wild pointer protection;
and if any object in the program needs to be protected by the wild pointer, adding an identifier to the any object, and taking the object added with the identifier as the target object.
3. The method according to claim 2, wherein whether the respective object needs to be protected by a wild pointer is determined according to the type of the respective object.
4. The method of claim 2, wherein the step of determining whether each object in the program requires wild pointer protection comprises:
replacing the method for creating the respective object by the defined new method;
and judging whether each object needs to carry out wild pointer protection or not in the new method.
5. The method of claim 2, wherein the step of adding an identification to the any object comprises:
adding the identification to the any object based on a function that dynamically adds the associated object.
6. The method of claim 1, further comprising:
and releasing the related attribute referenced by the target object when determining to perform time-delay destruct on the target object.
7. The method of claim 1, wherein intercepting the method originally sent to the target object based on the specified class and forwarding to the null function pointer comprises:
intercepting a method originally sent to the target object through a message forwarding function in the specified class, and returning to an object class;
and dynamically adding a class method to the object class, and pointing a pointer of the class method to a null function.
8. The method of claim 1, further comprising:
acquiring the class name of the original class stored in the target object;
and according to the acquired class name, counting error data generated in the running process of the program.
9. A medium having stored thereon a program which, when executed by a processor, carries out the method of any one of claims 1 to 8.
10. A destructuring device of a subject, comprising:
the destructor is used for performing delayed destructor on the target object when the life cycle of the target object is finished;
the processing unit is used for forwarding the method originally sent to the target object to a null function pointer within a time period for performing delay analysis on the target object;
the second judgment unit is used for judging whether the program is switched to the background operation or not and judging whether the number of the target objects of the delay analysis structure reaches a preset number or not;
when the program is judged to be switched to the background operation and the quantity of the target objects subjected to the delayed destruct is judged to reach the preset quantity, the original function of releasing the memory of the target objects subjected to the delayed destruct is called to destruct the target objects;
wherein, the processing unit includes:
the modification unit is used for modifying the class pointed by the function pointer of the target object into a specified class and storing the class name of the original class of the target object into the target object; wherein the function pointer originally points to an original class of the target object;
and the intercepting unit is used for intercepting the method originally sent to the target object based on the specified class and forwarding the method to the null function pointer.
11. The apparatus of claim 10, further comprising:
the first judgment unit is used for judging whether each object in the program needs to carry out wild pointer protection or not;
and an adding unit, configured to add an identifier to any object in the program when the first determining unit determines that the object needs to perform wild pointer protection, and take the object to which the identifier is added as the target object.
12. The apparatus of claim 11, wherein the first determining unit is configured to: and judging whether each object needs to carry out wild pointer protection or not according to the type of each object.
13. The apparatus of claim 11, wherein the first determining unit is configured to:
replacing the method for creating the respective object by the defined new method;
and judging whether each object needs to carry out wild pointer protection or not in the new method.
14. The apparatus of claim 11, wherein the adding unit is configured to: adding the identification to the any object based on a function that dynamically adds the associated object.
15. The apparatus of claim 10, the deconstruction unit to further: and releasing the related attribute referenced by the target object when determining to perform time-delay destruct on the target object.
16. The apparatus of claim 10, wherein the intercepting unit is configured to:
intercepting a method originally sent to the target object through a message forwarding function in the specified class, and returning to an object class;
and dynamically adding a class method to the object class, and pointing a pointer of the class method to a null function.
17. The apparatus of claim 10, further comprising:
the acquisition unit is used for acquiring the class name of the original class stored in the target object;
and the counting unit is used for counting error data generated in the running process of the program according to the acquired class name.
18. A computing device, comprising: a processor and a memory, the memory storing executable instructions, the processor to invoke the memory-stored executable instructions to perform the method of any of claims 1 to 8.
CN201710966413.9A 2017-10-17 2017-10-17 Destructor methods, media, devices and computing devices of objects Expired - Fee Related CN107741891B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710966413.9A CN107741891B (en) 2017-10-17 2017-10-17 Destructor methods, media, devices and computing devices of objects

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710966413.9A CN107741891B (en) 2017-10-17 2017-10-17 Destructor methods, media, devices and computing devices of objects

Publications (2)

Publication Number Publication Date
CN107741891A CN107741891A (en) 2018-02-27
CN107741891B true CN107741891B (en) 2020-12-08

Family

ID=61237667

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710966413.9A Expired - Fee Related CN107741891B (en) 2017-10-17 2017-10-17 Destructor methods, media, devices and computing devices of objects

Country Status (1)

Country Link
CN (1) CN107741891B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108469993B (en) * 2018-04-04 2021-04-27 武汉斗鱼网络科技有限公司 Message forwarding method, computer-readable storage medium and electronic device
CN111240850A (en) * 2018-11-29 2020-06-05 北京京东尚科信息技术有限公司 Function calling method and device, electronic equipment and storage medium
CN109992482B (en) * 2019-04-11 2023-10-31 广州方硅信息技术有限公司 Method, device, computer equipment and storage medium for observing middleware destructor
CN110851187B (en) * 2019-11-19 2023-06-02 北京百度网讯科技有限公司 Video memory processing method, device, equipment and medium
CN114860499B (en) * 2022-06-02 2025-09-02 中国工商银行股份有限公司 A method and device for determining wild pointer

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5918235A (en) * 1997-04-04 1999-06-29 Hewlett-Packard Company Object surrogate with active computation and probablistic counter
CN101046755A (en) * 2006-03-28 2007-10-03 郭明南 System and method of computer automatic memory management

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106708737B (en) * 2016-12-21 2020-06-26 腾讯科技(深圳)有限公司 Test method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5918235A (en) * 1997-04-04 1999-06-29 Hewlett-Packard Company Object surrogate with active computation and probablistic counter
CN101046755A (en) * 2006-03-28 2007-10-03 郭明南 System and method of computer automatic memory management

Also Published As

Publication number Publication date
CN107741891A (en) 2018-02-27

Similar Documents

Publication Publication Date Title
CN107741891B (en) Destructor methods, media, devices and computing devices of objects
US10915637B2 (en) Method, client, and system for testing application
US10481964B2 (en) Monitoring activity of software development kits using stack trace analysis
US10019581B2 (en) Identifying stored security vulnerabilities in computer software applications
US20150096025A1 (en) System, Apparatus and Method for Using Malware Analysis Results to Drive Adaptive Instrumentation of Virtual Machines to Improve Exploit Detection
CN104992117B (en) The anomaly detection method and behavior model method for building up of HTML5 mobile applications
US20190377877A1 (en) Web browser script monitoring
CN104834588B (en) The method and apparatus for detecting resident formula cross site scripting loophole
CN105760761A (en) Software behavior analyzing method and device
CN114116078A (en) Application data processing method, device, equipment and medium based on micro front end
US20210150022A1 (en) Command injection identification
CN115174192A (en) Application security protection method and device, electronic equipment and storage medium
US10581878B2 (en) Detection of cross-site attacks using runtime analysis
CN113127336B (en) Data collection method and device
CN110162982B (en) Method and device for detecting illegal rights, storage medium and electronic equipment
CN117668904A (en) Data desensitization method and device
CN114490264B (en) File monitoring method, device, electronic device and storage medium for application system
CN113872919B (en) A vulnerability scanning method and device
CN109684846A (en) A file extraction method and device
CN115292707A (en) Credibility judgment method and device based on dynamic class call sequence
CN114238021A (en) SDK interface positioning method, device, equipment and computer storage medium
CN113778800A (en) Error reporting information processing method, device, system, equipment and storage medium
CN105404586A (en) Event trigger and event triggering method
CN111414253A (en) Garbage collection GC information processing method, Java virtual machine and computer storage medium
CN119646803B (en) Security detection method, device, server and medium for application program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20201208