Object reference management method and device, equipment and storage medium

Through the reference manager, the reference manager manages the reference value and cross-reference value of the object, the resource leakage problem caused by cross-reference between objects is solved, and the accurate detection of the object state and the correct release of resources is achieved.

CN119718482AActive Publication Date: 2025-03-28GUANGZHOU ZHIYUAN ELECTRONICS CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510216521.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-26
Publication Date
2025-03-28
Estimated Expiration
2045-02-26

AI Technical Summary

Technical Problem

In the prior art, when there is cross reference between objects, the unused state of the object cannot be accurately judged, resulting in the reference count being unable to be reset to zero, and the object's destruction callback function cannot be triggered correctly, resulting in resource leakage and memory occupied.

Method used

The reference manager manages the reference values ​​and cross-reference values ​​of each object. When the reference values ​​and cross-reference values ​​of the object are detected to be equal to the preset value, determine that the object is in an unused state and log out the object to correctly free memory resources.

Benefits of technology

It realizes accurate detection of the usage or unused state of the object, avoids resource leakage and memory occupation, and ensures that the object correctly releases resources when it is not used.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718482A_ABST
    Figure CN119718482A_ABST
Patent Text Reader

Abstract

The invention discloses an object reference management method and device, equipment and a storage medium. According to the method, the reference manager creates the reference node of the newly-added object, the reference value and the cross reference value of the reference node of the newly-added object are initialized, and the reference manager correspondingly increases or decreases the reference value of the corresponding reference node when the object is referenced or released; a cross binding item of an object array is created through a reference manager, a cross reference value of each reference node in the cross binding item is increased, the object array comprises a plurality of objects with a cross reference relationship, and the cross binding item comprises reference nodes corresponding to each object in the object array. The reference manager reduces the cross reference value of the corresponding reference node when the reference value of each reference node in the cross binding item is equal to a preset value; and when the reference manager detects that both the reference value and the cross reference value of the reference node are equal to the preset numerical values, the object corresponding to the reference node is cancelled, and accurate detection of the unused state of the object is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an object reference management method, apparatus, device and storage medium. Background Art

[0002] In C language, an object is defined as an area in memory that stores data. The data stored in this area can be referenced by a variable name or a pointer. Object management mainly includes the creation, use, maintenance and destruction of objects. The entire process from the creation to the destruction of an object is the life cycle of the object. Object management can also be understood as the life cycle of the managed object.

[0003] In the prior art, reference counting is a commonly used technology to automatically manage the life cycle of objects. Through reference counting, the number of times each object is referenced can be tracked. When the reference count reaches zero, the object's destruction callback function is automatically triggered to release resources. Reference counting performs well when processing the life cycle of a single object. However, when there are cross-references between objects, the simple reference counting mechanism cannot correctly handle the timing of object destruction, resulting in the reference count being unable to return to zero, unable to accurately determine the unused state of the object, and then unable to trigger the destruction callback function when the object is in an unused state, resulting in resource leakage and memory occupation. Summary of the invention

[0004] The present application provides an object reference management method, apparatus, device and storage medium, which manage the reference value and cross-reference value of each object through a reference manager, and determine that the object is in an unused state when it is detected that the reference value and cross-reference value of the object are equal to preset values, so as to cancel the object to correctly release memory resources, thereby solving the problem in the prior art that the unused state of the object cannot be accurately judged when there are cross-references between objects, and effectively avoiding resource leakage and memory occupation.

[0005] In a first aspect, the present application provides an object reference management method, comprising: Creating a reference node of a newly added object through a reference manager, initializing a reference value and a cross-reference value of the reference node of the newly added object, and the reference manager correspondingly increasing or decreasing a reference value of a corresponding reference node when the object is referenced or released; Creating a cross-binding item of an object array through a reference manager, increasing a cross-reference value of each reference node in the cross-binding item, wherein the object array includes a plurality of objects having a cross-reference relationship, the cross-binding item includes a reference node corresponding to each object in the object array, and the reference manager reduces the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; When the reference manager detects that the reference value and the cross-reference value of the reference node are both equal to preset values, the object corresponding to the reference node is deregistered.

[0006] In a second aspect, the present application provides an object reference management device, including: A reference node management module is configured to create a reference node of a newly added object through a reference manager, initialize a reference value and a cross-reference value of the reference node of the newly added object, and the reference manager correspondingly increases or decreases the reference value of the corresponding reference node when the object is referenced or released; a cross-binding item management module configured to create a cross-binding item of an object array through a reference manager, increase a cross-reference value of each reference node in the cross-binding item, wherein the object array includes a plurality of objects having a cross-reference relationship, the cross-binding item includes a reference node corresponding to each object in the object array, and the reference manager reduces the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; The object deregistration module is configured to deregister the object corresponding to the reference node when the reference manager detects that the reference value and the cross-reference value of the reference node are both equal to preset values.

[0007] In a third aspect, the present application provides an object reference management device, including: One or more processors; a storage device storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the object reference management method as described in the first aspect.

[0008] In a fourth aspect, the present application provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute the object reference management method as described in the first aspect.

[0009] In the present application, a reference node of a newly added object is created through a reference manager, and the reference value and cross-reference value of the reference node of the newly added object are initialized. The reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released; a cross-binding item of an object array is created through a reference manager, and the cross-reference value of each reference node in the cross-binding item is increased. The object array includes multiple objects with a cross-reference relationship, and the cross-binding item includes reference nodes of each object in the corresponding object array. The reference manager decreases the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; when the reference manager detects that the reference value and cross-reference value of the reference node are equal to the preset value, the object corresponding to the reference node is deregistered. Through the above technical means, the reference manager manages the reference node of the object and the cross-binding item of the object array with a cross-reference relationship. The reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released, so as to accurately record the individual reference of the object through the reference value. When the reference manager detects that the reference value of each reference node in the cross-binding item reaches a preset value, it confirms that the reference nodes in the cross-binding item end cross-referencing each other, thereby reducing the cross-reference value of each reference node in the cross-binding item, so as to accurately determine the cross-reference status of the object through the cross-reference value. When the reference manager detects that the reference value and cross-reference value of the object are both equal to the preset value, it confirms that the object is currently not in use, and realizes accurate detection of the used state or unused state of the object, solving the problem in the prior art that the unused state of the object cannot be accurately determined when there are cross-references between objects, thereby triggering the destruction callback function to destroy the unused object at the right time, effectively avoiding resource leakage and memory occupation. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] Figure 1 is a flow chart of an object reference management method provided by an embodiment of the present application; Figure 2 is a schematic diagram of the internal resources of the reference manager provided in the embodiment of the present application; Figure 3 is a flowchart of triggering a reference manager to perform a garbage collection operation according to a reference value provided by an embodiment of the present application; Figure 4 This is a flowchart of a reference manager processing junk nodes provided by an embodiment of the present application; Figure 5 is a schematic diagram of the management process of the reference manager provided in an embodiment of the present application; Figure 6 It is a structural diagram of an object reference management device provided in an embodiment of the present application; Figure 7 It is a structural diagram of an object reference management device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0011] In order to make the purpose, technical scheme and advantages of the present application clearer, the specific embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. It is understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for the convenience of description, only part of the present application is shown in the accompanying drawings, but not all of the content. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow chart describes each operation (or step) as a sequential process, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of each operation can be rearranged. The process can be terminated when its operation is completed, but it can also have additional steps not included in the accompanying drawings. The process can correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.

[0012] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0013] In the existing relatively similar implementation methods, objects in C language are usually represented by structures, and the reference count is maintained as a member variable of the structure. When the external environment obtains a reference to an object, the reference count increases, and when the external environment releases the reference to the object, the reference count decreases. When the reference count is reduced to 0, the object's destruction callback function is automatically triggered to release the object resources. The traditional reference counting method performs well when dealing with the life cycle of a single object, but the emergence of cross-references makes the life cycle management of objects complicated and prone to errors. If the references between objects form a closed-loop reference, that is, a cross-reference (such as object A references object B, and object B references object A), even if the object is no longer referenced by the external environment, its reference count will not drop to zero, and it is impossible to accurately determine the unused state of the object, and then it is impossible to trigger the destruction callback function when the object is in an unused state, resulting in resource leakage and memory occupation. To avoid this situation, programmers usually need to use additional logic to track and manage the reference relationship of objects, which greatly increases the complexity and maintenance difficulty of the code.

[0014] To solve the above problem, the present embodiment provides an object reference management method, which manages the reference value and cross-reference value of each object through a reference manager, and determines that the object is not in use when it is detected that the reference value and cross-reference value of the object are equal to the preset value, so as to deregister the object to correctly release memory resources, effectively avoiding resource leakage and memory occupation.

[0015] The object reference management method provided in this embodiment can be executed by an object reference management device, which can be implemented by software and / or hardware. The object reference management device can be composed of two or more physical entities, or can be composed of one physical entity. For example, the object reference management device can be an intelligent terminal with strong processing capabilities such as a computer and a server. Among them, the server can be implemented as an independent server or a server cluster composed of multiple servers.

[0016] The object reference management device is installed with at least one type of operating system, and the object reference management device can install at least one application based on the operating system, and the application can be an application that comes with the operating system, or an application downloaded from a third-party device or server. In this embodiment, the object reference management device is installed with at least an application that can execute the object reference management method.

[0017] For ease of understanding, this embodiment is described by taking a computer as an example of a subject that executes the object reference management method.

[0018] Figure 1 A flowchart of an object reference management method provided by an embodiment of the present application is given. Figure 1 , the object reference management method specifically includes: S110. Create a reference node for the newly added object through the reference manager, initialize the reference value and cross-reference value of the reference node for the newly added object, and the reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released.

[0019] Among them, the reference manager is responsible for managing the reference nodes of the object and the cross-binding items of the object array. The object array includes multiple objects that have a cross-reference relationship. For example, when object A and object B reference each other, object A and object B are in the same object array. The cross-binding items contain reference nodes for each object in the corresponding object array. In the process of managing the reference nodes of the object and the cross-binding items of the object array, the reference manager can adaptively adjust the reference value and cross-reference value of the reference node, thereby reflecting the usage of the object through the reference value and cross-reference value. Among them, the reference value of the reference node is used to represent the situation where the corresponding object is currently referenced by the external environment, and the cross-reference value is used to represent the situation where other objects that have a cross-reference relationship with the corresponding object are referenced by the external environment.

[0020] Exemplarily, when a new object is created in a certain external environment, a reference node of the new object is created through a reference manager, and the reference value and cross-reference value of the reference node of the new object are initialized to obtain an initial reference value and an initial cross-reference value. The initial reference value can be set to a negative integer, such as -1 or -2, so that the object corresponding to the reference node is represented as a new object by a negative integer, so as to avoid the reference manager from clearing the reference node of the new object as a garbage node when clearing garbage nodes. The initial cross-reference value can be set to zero, so that zero is used to represent that the object corresponding to the reference node has no interactive reference relationship with other objects.

[0021] Optionally, the reference manager stores the reference nodes of each object through a node list. After creating the reference node of the newly added object, the reference manager adds the reference node to the node list. It should be noted that when the object of the reference node is a newly added object or is referenced externally, it will be saved in the node list. Once a non-newly added object is not referenced externally, the corresponding reference node will be deleted from the node list as a garbage node to avoid unlimited increase of reference nodes in the node list and improve the management convenience of the reference manager.

[0022] The reference manager provides an initialization interface to initialize the reference manager. Specifically, call the reference manager's initialization interface to create the reference manager's node list and cross-binding list. Since the node list and cross-binding list are initially created, they do not store reference nodes and cross-binding items. After that, initialize the reference manager's mutex lock so that each subsequent call to the reference manager's interface uses the mutex lock to lock the reference manager's interface and perform an unlocking operation before exiting the interface to protect the reference manager's resources from being safely accessed by multiple threads. For example, Figure 2 Schematic diagram of the internal resources of the reference manager provided in the embodiment of the present application. Figure 2 As shown, the internal resources of the reference manager include a mutex, a node list and a cross-binding list. The node list is used to store reference nodes of newly added objects or externally referenced objects, and the cross-binding item list is used to store cross-binding items of newly added objects or externally referenced objects.

[0023] Optionally, the reference manager also provides an add object interface. After adding a new object, the external environment can call the add object interface to create a reference node for the newly added object in the reference manager. The specific implementation process is: call the add object interface of the reference manager to pass the object pointer and destruction callback function of the newly added object as parameters to the reference manager, and the reference manager creates a reference node for the newly added object, and saves the object pointer and destruction callback function of the corresponding object in the reference node. Exemplarily, after the external environment creates a new object, it will obtain an object pointer and a destruction callback function. The object pointer is used to point to the corresponding object, and the destruction callback function is used to release the object resources when the object is no longer used externally. The external environment calls the add object interface of the reference manager to pass the object pointer and destruction callback function of the newly added object as parameters to the reference manager. After receiving the object pointer and destruction callback function of the newly added object through the add object interface, the reference manager creates a reference node for the newly added object in the node list, and saves the object pointer, destruction callback function, initial reference value, and initial cross-reference value of the newly added object in the reference node. Reference Figure 2 ,Any reference node in the node list stores the reference value, cross reference value, object pointer and destruction callback function of the corresponding object.

[0024] It should be noted that when the reference manager supports multi-threaded access, the interface of the reference manager is locked by a mutex when called and unlocked when exited. For example, before the external environment calls the reference manager's add object interface to create a reference node for a newly added object, it will use the reference manager's mutex to lock the add object interface to prevent other external environments from accessing the reference manager at the same time. After that, after the reference manager creates the reference node for the newly added object, it will feedback the successful node creation information to the external environment. After receiving the corresponding feedback, the external environment will unlock the add object interface. The unlocked add object interface can be accessed by other external environments.

[0025] After creating the reference node of the object, the reference manager can increase or decrease the reference value of the reference node of the object according to the reference or release of the object by the external environment. Optionally, the reference value of the object is monotonically increased and monotonically decreased according to the first preset value, so that the ratio of the reference value of the reference node to the first preset value can accurately represent the number of times the object is currently referenced. That is, when the object is referenced by the external environment for the first time, the reference value of the object is increased from a negative integer to the first preset value, and then the reference value is increased by the first preset value each time it is referenced by the external environment, and the reference value is reduced by the first preset value each time it is released by the external environment. For example, the initial reference value of the object is -1, and when the object is referenced by the external environment for the first time, the reference value of the object is increased from -1 to 1, and then the reference value is increased by 1 each time it is referenced by the external environment, and the reference value is reduced by 1 each time it is released by the external environment. The ratio of the reference value of the reference node to the first preset value can accurately represent the number of times the object is currently referenced. If the object of the reference node is referenced by two external environments in succession and then released by one of the external environments, the reference value of the reference node is 1, which indicates that there is still an external environment that references the object of the reference node. This embodiment is described by taking the initial reference value of -1 and the first preset value of 1 as an example.

[0026] Optionally, the reference manager also provides an add reference interface. Before the external environment references an object, it can call the add reference interface of the reference manager to notify the reference manager that it wants to reference the object, so that the reference manager can increase the reference value of the reference node of the referenced object. The specific implementation process is: before referencing the object, call the add reference interface of the reference manager to pass the object pointer of the object as a parameter to the reference manager, and the reference manager determines the reference node of the object according to the received object pointer, and increases the reference value of the corresponding reference node. Exemplarily, before the external environment references a certain object, call the add reference interface of the reference manager to pass the object pointer of the object to be referenced as a parameter to the reference manager. After receiving the object pointer through the add reference interface, the reference manager confirms that the object pointed to by the object pointer is about to be referenced by the external environment, thereby searching for the reference node that stores the object pointer according to the object pointer, and determining the reference node found as the reference node of the object to be referenced by the external environment. If the reference value of the reference node is -1, the reference value of the reference node is increased to 1, and if the reference value of the reference node is not -1, the reference value of the reference node is increased by 1. After increasing the reference value of the reference node, the reference manager feeds back information about the successful addition of the reference value to the external environment through the reference interface. After receiving the feedback from the reference manager, the external environment starts to reference the object.

[0027] It should be noted that when the reference manager supports multi-threaded access, before the external environment calls the reference manager's add reference interface, it will use the reference manager's mutex lock to lock the add reference interface to prevent other external environments from accessing the reference manager at the same time. Afterwards, after the reference manager adds the reference value of the object to be referenced, it will feedback the information that the reference value has been successfully added to the external environment. After receiving the corresponding feedback, the external environment will unlock the add reference interface. The unlocked add reference interface can be accessed by other external environments.

[0028] Optionally, the reference manager also provides a reference reduction interface. Before the external environment releases the object, the reference manager's reference reduction interface can be called to notify the reference manager that it is going to release the object so that the reference manager can reduce the reference value of the reference node of the released object. The specific implementation process is: before releasing the object, the reference manager's reference reduction interface is called to pass the object pointer of the object to the reference manager, and the reference manager determines the object's reference node according to the received object pointer, and reduces the reference value of the corresponding reference node. Exemplarily, before releasing an object, the external environment calls the reference manager's reference reduction interface to pass the object pointer of the object to be released as a parameter to the reference manager. After receiving the object pointer through the reference reduction interface, the reference manager confirms that the object pointed to by the object pointer is about to be released by the external environment, and then searches for the reference node that stores the object pointer according to the object pointer, and determines the found reference node as the reference node of the object to be released by the external environment, and reduces the reference value of the reference node by 1. After reducing the reference value of the reference node, the reference manager feeds back information that the reference value is successfully reduced to the external environment through the reference reduction interface, and the external environment starts to release the object after receiving the feedback from the reference manager.

[0029] It should be noted that when the reference manager supports multi-threaded access, before the external environment calls the reference manager's reduce reference interface, it will use the reference manager's mutex lock to lock the reduce reference interface to prevent other external environments from accessing the reference manager at the same time. Afterwards, after the reference manager reduces the reference value of the object to be released, it will feedback the information that the reference value has been successfully reduced to the external environment. After receiving the corresponding feedback, the external environment unlocks the reduce reference interface. The unlocked reduce reference interface can be accessed by other external environments.

[0030] S120. Create a cross-binding item of the object array through the reference manager, increase the cross-reference value of each reference node in the cross-binding item, the object array includes multiple objects with a cross-reference relationship, the cross-binding item includes reference nodes corresponding to each object in the object array, and the reference manager reduces the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value.

[0031] Exemplarily, when the external environment cross-references multiple objects, an object array may be created based on the multiple cross-referenced objects, and a cross-binding item of the object array may be created through a reference manager. When creating the cross-binding item, the reference manager may generate a node array of reference nodes of each object in the corresponding object array and save it in the cross-binding item. After creating the cross-binding item of the object array, the cross-reference value of each reference node in the cross-binding item may be increased by a first preset value, so that the ratio of the cross-reference value of the reference node to the first preset value represents how many groups of objects the corresponding object has a cross-reference relationship with.

[0032] It should be noted that cross-reference refers to the existence of a mutual reference relationship between multiple objects, that is, any object among the multiple objects with a cross-reference relationship is referenced by the remaining objects. For example, if object A, object B, and object C have a cross-reference relationship, then object A and object B are referenced by object C, object B and object C are referenced by object A, and object A and object C are referenced by object C.

[0033] For example, after establishing a cross-reference relationship among object A, object B, and object C, object A, object B, and object C are placed in the same object array. Multiple objects with a cross-reference relationship may be created by the same external environment or by different external environments. When multiple objects with a cross-reference relationship are created by different external environments, one of the external environments places multiple objects in the same object array, and a cross-binding item of the object array is created through a reference manager. Assume that object A, object B, and object C are created by external environment A, external environment B, and external environment C, respectively. After external environment A, external environment B, or external environment C establishes a cross-reference relationship among object A, object B, and object C, object A, object B, and object C are placed in an object array, and a cross-binding item of the object array is created through a reference manager. Since the corresponding external environment will create corresponding reference nodes in the reference manager when objects A, B and C are initially created, the reference manager can directly obtain the reference nodes of objects A, B and C from the node list and save them to the cross-binding item when creating the cross-binding item, and then increase the cross-reference value of the reference nodes of objects A, B and C by 1.

[0034] Of course, an object may not have a cross-reference relationship with other objects, in which case the cross-reference value of the object will remain at the initial cross-reference value, which is equal to 0. Once the external environment establishes a cross-reference relationship between the object and other objects, a cross-binding item between the object and other objects will be created in the reference manager accordingly, and the cross-reference value of the object's reference node will be increased to 1, indicating that the object currently has a cross-reference relationship with a group of objects.

[0035] refer to Figure 2When creating a cross-binding item of an object array, the reference manager creates a cross-binding item of the object array in the cross-binding list, puts the reference nodes of each object in the object array into a node array, and saves the node array in the cross-binding item. In addition, the number of nodes in the node array is counted, and the number of nodes is saved in the cross-binding item.

[0036] Optionally, the reference manager also provides a cross-binding interface, and the external environment can call the cross-binding interface to create a cross-binding item of the object array in the reference manager. The specific implementation process is: add multiple objects with a cross-reference relationship to an object array, call the cross-binding interface of the reference manager to pass the object array as a parameter to the reference manager, and the reference manager creates a cross-binding item of the object array, obtains the corresponding reference node according to each object in the object array, and saves the obtained reference node in the cross-binding item. Exemplarily, after establishing a cross-reference relationship between multiple objects, the external environment puts multiple objects into an object array, wherein the object put into the object array can be an object pointer pointing to the object. The external environment calls the cross-binding interface of the reference manager to pass the object array as a parameter to the reference manager, and the reference manager queries the corresponding reference node in the node list according to the object pointer in the object array transmitted by the cross-binding interface, puts the queried reference node into a node array, creates a cross-binding item of the object array in the cross-binding list, and stores the node array in the cross-binding item. Then, the cross-reference value of the queried reference node is increased by 1. In addition, the external environment can determine the corresponding number of objects based on the object array, and transmit the object number and the object array to the reference manager through the cross-binding interface. After creating the cross-binding item of the object array, the reference manager stores the object number as the node number of the node array in the cross-binding item.

[0037] It should be noted that when the reference manager supports multi-threaded access, before the external environment calls the cross-binding interface of the reference manager, it will use the reference manager's mutex lock to lock the cross-binding interface to prevent other external environments from accessing the reference manager at the same time. After that, after the reference manager creates the cross-binding items of the object array and increases the cross-reference value of the reference node, it will feedback the information that the cross-binding item was successfully created to the external environment. After receiving the corresponding feedback, the external environment unlocks the cross-binding interface. The unlocked cross-binding interface can be accessed by other external environments.

[0038] In this embodiment, the preset value is equal to the initial value of the cross-reference value, that is, the preset value is the same as the initial value of the cross-reference value, and is generally set to 0. When the reference values ​​of each reference node in the cross-binding item are all equal to zero, it indicates that the object of each reference node in the cross-binding item is no longer called by the external environment, and accordingly, the objects of each reference node in the cross-binding item do not have a mutual reference relationship. The object reduces a group of cross-reference relationships, so the cross-reference value of the reference node of the object is reduced by a first preset value, so that the ratio of the reduced cross-reference value to the first preset value represents how many groups of objects the corresponding object has a cross-reference relationship with. And, when the reference values ​​of each reference node in the cross-binding item are all equal to zero, the cross-binding item is deleted from the cross-binding list to indicate that the objects of each reference node in the cross-binding item no longer have a cross-reference relationship, and to avoid the unlimited increase of cross-binding items in the cross-binding list, thereby improving the management convenience of the reference manager.

[0039] For example, assuming that the reference nodes of object A and object B are stored in cross-binding item X, and the reference nodes of object A and object C are stored in cross-binding item Y, if the reference value of object A and the reference value of object B are both equal to 0, it means that object A is no longer referenced by external direct code, and object B is no longer directly referenced by the external environment, indicating that there is no cross-reference relationship between object B and object A, that is, the cross-reference relationship between object B and object A has been reduced by one group, then the cross-reference values ​​of object B and object A are both reduced by 1. If object B only has a cross-reference relationship with object A, and object A has a cross-reference relationship with object B and object C respectively, then the cross-reference value of object B is equal to 0 after being reduced by 1, indicating that object B currently has no cross-reference relationship with any object. If the reference value of object C is not equal to 0, it means that object A will be indirectly referenced by other external environments through the reference of object C, that is, object A is still in use, but its cross-reference value is equal to 1, indicating that object A currently still has a cross-reference relationship with a group of objects. If and only if the reference value and cross-reference value of an object are both equal to the preset value, that is, equal to zero, it is confirmed that the object is not directly or indirectly referenced by the external environment, and the object will be destroyed. Therefore, if the reference value of object A is equal to zero, but the cross-reference value is greater than zero, object A will not be destroyed.

[0040] S130: When the reference manager detects that the reference value and the cross-reference value of the reference node are both equal to preset values, the object corresponding to the reference node is deregistered.

[0041] Exemplarily, the reference manager can traverse the reference value and cross-reference value of each reference node in the node list in real time. When it is detected that the reference value and cross-reference value of the reference node are both equal to zero, it is confirmed that the object corresponding to the reference node is not directly or indirectly referenced by the external environment, and the reference node is determined to be a garbage node. The corresponding object can be deregistered according to the destruction callback function saved by the garbage node, so as to achieve effective cleaning of unused objects and avoid resource leakage and memory occupation. When it is detected that the reference value or cross-reference value of the reference node is not equal to zero, it is confirmed that the object corresponding to the reference node is being directly or indirectly referenced by the external environment, and the reference node is determined to be a valid node.

[0042] Optionally, the reference value of a reference node may be equal to zero only during the reduction process. In order to reduce the workload of the reference manager, it may be determined whether to trigger the garbage collection operation of the reference manager based on the reference value after the reference value of the reference node is reduced, so that the cross-reference value of the reference node may be adjusted through the reference manager when the reference manager performs the garbage collection operation, and then garbage nodes whose reference value and cross-reference value are both equal to zero are detected. Figure 3 1 is a flowchart of triggering a reference manager to perform a garbage collection operation according to a reference value provided by an embodiment of the present application. Figure 3 As shown, the step of triggering the reference manager to perform garbage collection according to the reference value specifically includes S1301-S1303: S1301: The reference manager checks whether the reference value of the reference node is equal to a preset value.

[0043] Exemplarily, after reducing the reference value of the reference node by 1, the reference manager may determine whether the reference value of the reference node is equal to zero. If it is not equal to zero, the reference manager waits for the next external environment to call the reference reduction interface to reduce the reference value before making the determination in step S1301. If the reference value is equal to zero, it indicates that the object of the reference node is no longer directly referenced by the external environment, and then further determines whether the object of the reference node is indirectly referenced by the external environment.

[0044] S1302. When the reference value of the reference node is equal to a preset value, the reference manager checks whether the reference value of each reference node in the cross-binding item is equal to the preset value. If so, the reference manager reduces the cross-reference value of each reference node in the cross-binding item and deletes the cross-binding item.

[0045] Exemplarily, when the reference value of a reference node is equal to zero, the object of the reference node is no longer directly referenced by the external environment, and other objects that reference the object will not be indirectly referenced by the external environment through the object (for example, when object A and object B are cross-referenced, if the reference value of object A is equal to zero, then object B will not be indirectly referenced by the external environment through object A). Therefore, it is necessary to check the reference value of each reference node in each cross-binding item where the reference node is located to determine whether the object corresponding to the reference node in the cross-binding item still has a cross-reference relationship. If the reference values ​​of all reference nodes in the cross-binding item are equal to zero, it indicates that the object corresponding to the reference node in the cross-binding item no longer has a cross-reference relationship. At this time, the reference manager reduces the cross-reference value of each reference node in the cross-binding item by 1, and then deletes the cross-binding item.

[0046] For example, assuming that the reference nodes of object A and object B are in cross-binding item X, and the reference nodes of object A and object C are in cross-binding item Y, if the reference value of object A is equal to 0 after reducing the reference value of object A, then check whether the reference values ​​of the reference nodes of object A and object B in the cross-binding item X where object A is located are both equal to zero, and check whether the reference values ​​of the reference nodes of object A and object C in the cross-binding item Y where object A is located are both equal to zero. If the reference values ​​of the reference nodes of object A and object B are both equal to zero, then reduce the cross-reference values ​​of the reference nodes of object A and object B by 1, and delete the cross-binding item X; if the reference value of the reference node of object A is equal to zero, and the reference value of the reference node of object C is not equal to zero, then do not adjust the cross-reference values ​​of the reference nodes of object A and object C. It should be noted that if it is detected that the reference values ​​of each reference node in the N cross-binding items where the reference node is located are all equal to zero, then the cross-reference value of the reference node is reduced by N in total.

[0047] S1303: The reference manager checks whether the reference value and cross-reference value of each reference node are equal to a preset value.

[0048] Exemplarily, after reducing the cross-reference value of the reference node, the reference manager may traverse the reference value and cross-reference value of each reference node in the node list. When it is determined that the reference value and cross-reference value of the reference node are both equal to zero, it is confirmed that the object of the reference node is no longer directly or indirectly referenced by the external environment, thereby determining that the reference node is a garbage node. When the reference value or cross-reference value of the reference node is not equal to zero, it is confirmed that the object of the reference node is directly or indirectly referenced by the external environment, and the reference node is not determined as a garbage node.

[0049] Optionally, the reference manager provides an internal garbage collection interface to perform garbage collection operations. That is, when the reference manager determines that the reference value of a reference node is equal to zero, it calls the internal garbage collection interface to adjust the cross-reference value of the reference node, and then traverses the reference values ​​and cross-reference values ​​of each reference node in the node list, thereby determining the reference nodes whose reference values ​​and cross-reference values ​​are both equal to zero as garbage nodes, and then calls the destruction callback function saved by the garbage node to deregister the object of the garbage node.

[0050] It should be noted that when the reference manager supports multi-threaded access, the reference manager will use a mutex to lock the garbage collection interface when calling the garbage collection interface, and then unlock the garbage collection interface after the garbage collection operation is completed. However, the garbage collection interface is in a locked state when the reference manager performs the garbage collection operation. If the reference manager calls the destruction callback function in the garbage node to cancel the object of the garbage node when performing the garbage collection operation, the object will be locked when canceling the object, that is, the object will call the external mutex. However, when the garbage node is found, it is within the internal mutex protection range of the reference manager. No external mutex operation is allowed within this protection range, because the reference manager is a bottom-level, general functional module. If there is an external lock operation within the mutex protection range of the reference manager, a deadlock will occur. Therefore, when the reference manager performs the garbage collection operation, it only needs to execute the steps to find the garbage node, and does not cancel the object of the garbage node. Instead, it waits until the garbage collection interface is unlocked before canceling the object of the garbage node.

[0051] For example, Figure 4 Flowchart of the reference manager processing junk nodes provided by the embodiment of the present application. Figure 4 As shown, the steps of the reference manager processing junk nodes specifically include S1304-S1306: S1304: When the reference manager determines that the reference value of the reference node is equal to a preset value, a mutex lock is used to lock the garbage collection interface.

[0052] Exemplarily, after reducing the reference value of the reference node, the reference manager determines whether the reference value of the reference node is equal to zero. If it is equal to zero, it confirms that the garbage collection interface is about to be called to perform the garbage collection operation, and uses a mutex lock to lock the garbage collection interface before using the garbage collection interface.

[0053] S1305. The reference manager calls the garbage collection interface to create a list of nodes to be destroyed, adjusts the cross-reference value of the corresponding reference node according to the reference value of each reference node in each cross-binding item, and adds the reference node whose reference value and cross-reference value are equal to the preset value to the list of nodes to be destroyed.

[0054] Exemplarily, after the reference manager uses a mutex to lock the garbage collection interface, it calls the garbage collection interface to create a list of nodes to be destroyed, and the list of nodes to be destroyed is used to store garbage nodes whose reference values ​​and cross-reference values ​​are both equal to zero. Afterwards, the reference values ​​of each reference node of each cross-binding item in the cross-binding list are traversed. If it is determined that the reference values ​​of each reference node of a cross-binding item are all equal to zero, the cross-reference values ​​of each reference node of the cross-binding item are reduced by 1 and the cross-binding item is deleted. After reducing the cross-reference value of the reference node, the reference value and cross-reference value of each reference node in the node list are traversed, and the reference nodes whose reference values ​​and cross-reference values ​​are both equal to zero are added as garbage nodes to the list of nodes to be destroyed.

[0055] S1306: After unlocking the garbage collection interface, deregister the object corresponding to the referenced node in the list of nodes to be destroyed, and delete the corresponding referenced node and the list of nodes to be destroyed in the reference manager.

[0056] Exemplarily, after adding all garbage nodes to the list of nodes to be destroyed, the reference manager completes the garbage collection operation, and then unlocks the garbage collection interface to move the garbage nodes out of the mutex protection range of the reference manager. Afterwards, the objects of the garbage nodes are deregistered according to the destruction callback function saved by the garbage nodes in the list of nodes to be destroyed. After successfully deregistering the objects of the garbage nodes, the corresponding reference nodes are deleted from the node list of the reference manager. After deregistering the objects of all garbage nodes in the list of nodes to be destroyed, the list of nodes to be destroyed is deleted.

[0057] In order to more intuitively understand the process of managing object references through the reference manager in this embodiment, Figure 5 The management process of the reference manager shown in FIG. Figure 5As shown, external environment 1 creates object A and object B, and then calls the reference add interface to add object A and object B to the reference manager, so that the reference manager creates reference node A of object A in the node list to save the object pointer and object destruction callback function of object A, and creates reference node B of object B in the node list to save the object pointer and object destruction callback function of object B. Afterwards, when object A and object B need to cross-reference, external environment 1 puts object A and object B into an object array, calls the cross binding interface to pass the object array where object A and object B are located as a parameter to the reference manager, and the reference manager creates a cross binding item of the object array to store the reference nodes of the objects in the object array, and then adds the cross binding item to the cross binding list. Before using object A, external environment 1 calls the reference manager's add reference interface to notify the reference manager that it wants to reference object A. The reference manager searches for the reference node A of object A and adds 1 to the reference value of reference node A. Before using object B, external environment 1 calls the reference manager's add reference interface to notify the reference manager that it wants to reference object B. The reference manager searches for the reference node B of object B and adds 1 to the reference value of reference node B. After the reference manager increases the reference values ​​of reference node A and reference node B, external environment 1 can officially use object A and object B. Before external environment 2 uses object A, it calls the reference manager's add reference interface to notify the reference manager that it wants to reference object A. The reference manager finds the reference node A of object A and adds 1 to the reference value of reference node A. After the reference manager increases the reference value of reference node A, external environment 2 can officially use object A. After the work of external environment 1 is completed, it will start to release the previously referenced objects A and object B. Before releasing object A, it calls the reference manager's reduce reference interface to notify the reference manager that it wants to release object A. The reference manager finds the reference node A of object A, subtracts 1 from the reference value of reference node A, and then checks whether the reference value of reference node A is equal to 0. At this time, the reference value of reference node A is equal to 1, and the cross-reference value of reference node A is not adjusted. Before releasing object B, the reference manager's reference reduction interface is called to notify the reference manager that it is going to release object B. The reference manager looks for reference node B of object B, decrements the reference value of reference node B by 1, and then checks whether the reference value of reference node B is equal to 0. At this time, if the reference value of reference node B is equal to 0, then check whether the reference value of another reference node A in the cross-binding item where reference node B is located is equal to 0. If the reference value of reference node A is equal to 1 (external environment 2 is still referencing object A), then the cross-reference value of reference node A and reference node B is not adjusted. After that, external environment 1 releases object A and object B and exits the environment.After the external environment 2 completes its work, it will start to release the previously referenced object A. Before releasing object A, it calls the reference manager's reference reduction interface to notify the reference manager that it wants to release object A. The reference manager finds the reference node A of object A, decrements the reference value of reference node A by 1, and the external environment 2 releases object A and exits the environment. After that, the reference manager checks whether the reference value of reference node A is equal to 0. At this time, if the reference value of reference node A is equal to 0, it checks whether the reference value of another reference node B in the cross-binding item where reference node A is located is equal to 0. If the reference value of reference node B is equal to 0, then the cross-reference values ​​of reference node A and reference node B are both decremented by 1. At this time, the cross-reference values ​​of reference node A and reference node B are both equal to 0. Check the reference value and cross-reference value of reference node A and reference node B, and confirm that the reference value and cross-reference value of reference node A and reference node B are both equal to zero, then trigger the object destruction callback function in reference node A to destroy object A, and trigger the object destruction callback function in reference node B to destroy object B. After that, release reference node A and reference node B in the node list.

[0058] In summary, the object reference management method provided by the embodiment of the present application creates a reference node of a newly added object through a reference manager, initializes the reference value and cross-reference value of the reference node of the newly added object, and the reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released; creates a cross-binding item of an object array through a reference manager, increases the cross-reference value of each reference node in the cross-binding item, the object array includes multiple objects with a cross-reference relationship, the cross-binding item includes the reference nodes of each object in the corresponding object array, and the reference manager decreases the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; when the reference manager detects that the reference value and cross-reference value of the reference node are equal to the preset value, the object corresponding to the reference node is deregistered. Through the above technical means, the reference manager manages the reference node of the object and the cross-binding item of the object array with a cross-reference relationship, and the reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released, so as to accurately record the individual reference of the object through the reference value. When the reference manager detects that the reference value of each reference node in the cross-binding item reaches a preset value, it confirms that the reference nodes in the cross-binding item end cross-referencing each other, thereby reducing the cross-reference value of each reference node in the cross-binding item, so as to accurately determine the cross-reference status of the object through the cross-reference value. When the reference manager detects that the reference value and cross-reference value of the object are both equal to the preset value, it confirms that the object is currently not in use, and realizes accurate detection of the used state or unused state of the object, solving the problem in the prior art that the unused state of the object cannot be accurately determined when there are cross-references between objects, thereby triggering the destruction callback function to destroy the unused object at the right time, effectively avoiding resource leakage and memory occupation.

[0059] Based on the above embodiments, Figure 6 A schematic diagram of the structure of an object reference management device provided in an embodiment of the present application. Figure 6 The object reference management device provided in this embodiment specifically includes: a reference node management module 21, a cross-binding item management module 22 and an object deregistration module 23.

[0060] The reference node management module 21 is configured to create a reference node of a newly added object through a reference manager, initialize the reference value and cross-reference value of the reference node of the newly added object, and the reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released; The cross-binding item management module 22 is configured to create a cross-binding item of an object array through a reference manager, increase a cross-reference value of each reference node in the cross-binding item, the object array includes a plurality of objects having a cross-reference relationship, the cross-binding item includes a reference node corresponding to each object in the object array, and the reference manager reduces the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; The object deregistration module 23 is configured to deregister the object corresponding to the reference node when the reference manager detects that the reference value and the cross-reference value of the reference node are both equal to preset values.

[0061] Based on the above embodiment, the reference node management module 21 includes: a reference node creation unit, which is configured to call the add object interface of the reference manager to pass the object pointer and destruction callback function of the newly added object as parameters to the reference manager, and the reference manager creates a reference node for the newly added object, and saves the object pointer and destruction callback function of the corresponding object in the reference node.

[0062] Based on the above embodiment, the cross-binding item management module 22 includes: a cross-binding item creation unit, which is configured to add multiple objects with cross-reference relationships into an object array, call the cross-binding interface of the reference manager to pass the object array as a parameter to the reference manager, and the reference manager creates a cross-binding item for the object array, obtains the corresponding reference node according to each object in the object array, and saves the obtained reference node in the cross-binding item.

[0063] On the basis of the above embodiment, the reference node management module 21 includes: a reference value increasing unit, which is configured to call the reference manager's add reference interface to pass the object pointer of the object as a parameter to the reference manager before referencing the object, and the reference manager determines the reference node of the object according to the received object pointer, and increases the reference value of the corresponding reference node; and / or, a reference value decreasing unit, which is configured to call the reference manager's reduce reference interface to pass the object pointer of the object to the reference manager before releasing the object, and the reference manager determines the reference node of the object according to the received object pointer, and decreases the reference value of the corresponding reference node.

[0064] On the basis of the above embodiment, the cross-binding item management module 22 includes: a first judgment unit, configured to, after reducing the reference value of the corresponding reference node, check by the reference manager whether the reference value of the reference node is equal to a preset value; a cross-reference value reduction unit, configured to, when the reference value of the reference node is equal to the preset value, check by the reference manager whether the reference values ​​of each reference node in the cross-binding item are equal to the preset value, and if so, the reference manager reduces the cross-reference value of each reference node in the cross-binding item and deletes the cross-binding item; a second judgment unit, configured to, by the reference manager, check whether the reference value and cross-reference value of each reference node are equal to the preset value.

[0065] Based on the above embodiment, the reference manager supports multi-threaded access, and the interface of the reference manager performs a locking operation through a mutex lock when calling and an unlocking operation when exiting.

[0066] Based on the above embodiment, the cross-binding item management module 22 includes: a locking unit, configured to use a mutex lock to lock the garbage collection interface when the reference manager determines that the reference value of the reference node is equal to a preset value; a cross-reference value adjustment unit, configured to call the garbage collection interface by the reference manager to create a list of nodes to be destroyed, adjust the cross-reference value of the corresponding reference node according to the reference value of each reference node in each cross-binding item, and add the reference node whose reference value and cross-reference value are equal to the preset value to the list of nodes to be destroyed; the object cancellation module 23 includes: an object cancellation unit, configured to cancel the object corresponding to the reference node in the list of nodes to be destroyed after unlocking the garbage collection interface, and delete the corresponding reference node in the reference manager and the list of nodes to be destroyed.

[0067] As mentioned above, the object reference management device provided by the embodiment of the present application creates a reference node of a newly added object through a reference manager, initializes the reference value and cross-reference value of the reference node of the newly added object, and the reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released; creates a cross-binding item of an object array through a reference manager, increases the cross-reference value of each reference node in the cross-binding item, the object array includes multiple objects with a cross-reference relationship, the cross-binding item includes the reference nodes of each object in the corresponding object array, and the reference manager decreases the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; when the reference manager detects that the reference value and cross-reference value of the reference node are equal to the preset value, the object corresponding to the reference node is cancelled. Through the above technical means, the reference manager manages the reference node of the object and the cross-binding item of the object array with a cross-reference relationship, and the reference manager increases or decreases the reference value of the corresponding reference node when the object is referenced or released, so as to accurately record the individual reference of the object through the reference value. When the reference manager detects that the reference value of each reference node in the cross-binding item reaches a preset value, it confirms that the reference nodes in the cross-binding item end cross-referencing each other, thereby reducing the cross-reference value of each reference node in the cross-binding item, so as to accurately determine the cross-reference status of the object through the cross-reference value. When the reference manager detects that the reference value and cross-reference value of the object are both equal to the preset value, it confirms that the object is currently not in use, and realizes accurate detection of the used state or unused state of the object, solving the problem in the prior art that the unused state of the object cannot be accurately determined when there are cross-references between objects, thereby triggering the destruction callback function to destroy the unused object at the right time, effectively avoiding resource leakage and memory occupation.

[0068] The object reference management device provided in the embodiment of the present application can be used to execute the object reference management method provided in the above embodiment, and has corresponding functions and beneficial effects.

[0069] Figure 7 This is a schematic diagram of the structure of an object reference management device provided in an embodiment of the present application, with reference to Figure 7 The object reference management device includes: a processor 31, a memory 32, a communication device 33, an input device 34, and an output device 35. The number of processors 31 in the object reference management device can be one or more, and the number of memories 32 in the object reference management device can be one or more. The processor 31, memory 32, communication device 33, input device 34, and output device 35 of the object reference management device can be connected via a bus or other means.

[0070] The memory 32, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the object reference management method of any embodiment of the present application (for example, the reference node management module 21, the cross-binding item management module 22 and the object cancellation module 23 in the object reference management device). The memory 32 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the device, etc. In addition, the memory 32 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the device 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 a combination thereof.

[0071] The communication device 33 is used for data transmission.

[0072] The processor 31 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 32, that is, implements the above-mentioned object reference management method.

[0073] The input device 34 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the device. The output device 35 may include a display device such as a display screen.

[0074] The object reference management device provided above can be used to execute the object reference management method provided in the above embodiment, and has corresponding functions and beneficial effects.

[0075] An embodiment of the present application also provides a storage medium containing computer executable instructions. When the computer executable instructions are executed by a computer processor, they are used to execute an object reference management method. The object reference management method includes: creating a reference node of a newly added object through a reference manager, initializing the reference value and cross-reference value of the reference node of the newly added object, and the reference manager correspondingly increases or decreases the reference value of the corresponding reference node when the object is referenced or released; creating a cross-binding item of an object array through the reference manager, increasing the cross-reference value of each reference node in the cross-binding item, the object array includes multiple objects with a cross-reference relationship, the cross-binding item includes reference nodes corresponding to each object in the object array, and the reference manager decreases the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; when the reference manager detects that the reference value and cross-reference value of the reference node are equal to the preset value, the object corresponding to the reference node is deregistered.

[0076] Storage medium - any of various types of memory devices or storage devices. The term "storage medium" is intended to include: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (such as hard disk or optical storage); registers or other similar types of memory elements, etc. Storage media may also include other types of memory or combinations thereof. In addition, the storage medium may be located in the first computer system in which the program is executed, or may be located in a different second computer system, which is connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (for example, in different computer systems connected by a network). The storage medium may store program instructions (for example, embodied as a computer program) that can be executed by one or more processors.

[0077] Of course, the storage medium containing computer executable instructions provided in the embodiment of the present application is not limited to the object reference management method as described above, and the computer executable instructions can also execute related operations in the object reference management method provided in any embodiment of the present application.

[0078] The object reference management apparatus, object reference management system, storage medium and object reference management device provided in the above embodiments can execute the object reference management method provided in any embodiment of the present application. For technical details not described in detail in the above embodiments, please refer to the object reference management method provided in any embodiment of the present application.

[0079] The above are only preferred embodiments of the present application and the technical principles used. The present application is not limited to the specific embodiments herein, and various obvious changes, readjustments and substitutions that can be made by those skilled in the art will not deviate from the protection scope of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the claims.

Claims

1. An object reference management method, characterized in that: include: Creating a reference node of a newly added object through a reference manager, initializing a reference value and a cross-reference value of the reference node of the newly added object, and the reference manager correspondingly increasing or decreasing a reference value of a corresponding reference node when the object is referenced or released; Creating a cross-binding item of an object array through a reference manager, increasing a cross-reference value of each reference node in the cross-binding item, wherein the object array includes a plurality of objects having a cross-reference relationship, the cross-binding item includes a reference node corresponding to each object in the object array, and the reference manager reduces the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; When the reference manager detects that the reference value and the cross-reference value of the reference node are both equal to preset values, the object corresponding to the reference node is deregistered.

2. The object reference management method according to claim 1, characterized in that: The step of creating a reference node for the newly added object through the reference manager includes: The add object interface of the reference manager is called to pass the object pointer and destruction callback function of the newly added object as parameters to the reference manager, and the reference manager creates a reference node for the newly added object and saves the object pointer and destruction callback function of the corresponding object in the reference node.

3. The object reference management method according to claim 1, characterized in that: The step of creating a cross-binding item of an object array through a reference manager includes: Add multiple objects with cross-reference relationships to an object array, call the cross-binding interface of the reference manager to pass the object array as a parameter to the reference manager, and the reference manager creates a cross-binding item for the object array, obtains the corresponding reference node according to each object in the object array, and saves the obtained reference node in the cross-binding item.

4. The object reference management method according to claim 2, characterized in that: The method further comprises: Before referencing the object, the reference manager's add reference interface is called to pass the object pointer of the object as a parameter to the reference manager, and the reference manager determines the reference node of the object according to the received object pointer and increases the reference value of the corresponding reference node; and / or, Before releasing the object, the reference manager's reduce reference interface is called to pass the object pointer of the object to the reference manager, and the reference manager determines the reference node of the object according to the received object pointer and reduces the reference value of the corresponding reference node.

5. The object reference management method according to claim 4, characterized in that: After reducing the reference value of the corresponding reference node, the method further includes: The reference manager checks whether the reference value of the reference node is equal to a preset value; In the case where the reference value of the reference node is equal to a preset value, the reference manager checks whether the reference values ​​of each reference node in the cross-binding item are equal to the preset value, and if so, the reference manager reduces the cross-reference value of each reference node in the cross-binding item and deletes the cross-binding item; The reference manager checks whether the reference value and cross-reference value of each reference node are equal to a preset value.

6. The object reference management method according to claim 1, characterized in that: The reference manager supports multi-threaded access, and the interface of the reference manager performs a locking operation through a mutex lock when being called and performs an unlocking operation when exiting.

7. The object reference management method according to claim 6, characterized in that: Before deregistering the object corresponding to the reference node, the method further includes: When the reference manager determines that the reference value of the reference node is equal to a preset value, locking the garbage collection interface using a mutex lock; The reference manager calls the garbage collection interface to create a list of nodes to be destroyed, adjusts the cross-reference value of the corresponding reference node according to the reference value of each reference node in each cross-binding item, and adds the reference node whose reference value and cross-reference value are both equal to a preset value to the list of nodes to be destroyed; Unlocking the garbage collection interface; Correspondingly, deregistering the object corresponding to the reference node includes: After the garbage collection interface is unlocked, the object corresponding to the reference node in the list of nodes to be destroyed is deregistered, and the corresponding reference node in the reference manager and the list of nodes to be destroyed are deleted.

8. An object reference management device, characterized in that: include: A reference node management module is configured to create a reference node of a newly added object through a reference manager, initialize a reference value and a cross-reference value of the reference node of the newly added object, and the reference manager correspondingly increases or decreases the reference value of the corresponding reference node when the object is referenced or released; a cross-binding item management module configured to create a cross-binding item of an object array through a reference manager, increase a cross-reference value of each reference node in the cross-binding item, wherein the object array includes a plurality of objects having a cross-reference relationship, the cross-binding item includes a reference node corresponding to each object in the object array, and the reference manager reduces the cross-reference value of the corresponding reference node when the reference value of each reference node in the cross-binding item is equal to a preset value; The object deregistration module is configured to deregister the object corresponding to the reference node when the reference manager detects that the reference value and the cross-reference value of the reference node are both equal to preset values.

9. An object reference management device, characterized in that: include: one or more processors; A storage device stores one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the object reference management method as described in any one of claims 1-7.

10. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the object reference management method according to any one of claims 1 to 7 when executed by a computer processor.

Citation Information

Patent Citations

  • System and method of computer automatic memory management

    CN101046755A

  • Garbage object detecting method and device

    CN103226476A

  • Memory garbage collection method and device, and computer storage medium

    CN108804337A

  • Cache management method and device, medium and equipment

    CN114741335A

  • Lock free reference counting

    US6993770B1