Object reference management method, 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 release of objects and effective memory utilization is achieved.

CN119718482BActive Publication Date: 2025-08-15GUANGZHOU ZHIYUAN ELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In the prior art, when there is cross reference between objects, the reference count cannot accurately determine the unused state of the object, resulting in resource leakage and memory occupied.

Method used

Through the reference manager, the reference value and cross-reference value of the object are managed. When the reference value and cross-reference value are detected to be equal to the preset value, it is determined that the object is in an unused state and the object is logged out to achieve accurate release of the object.

Benefits of technology

It effectively avoids resource leakage and memory usage, ensuring the correct time for object destruction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718482B_ABST
    Figure CN119718482B_ABST
Patent Text Reader

Abstract

The present application discloses an object reference management method, apparatus, device, and storage medium. The present application creates a reference node for a newly added object through a reference manager, initializes the reference value and cross-reference value of the reference node for the newly added object, and correspondingly increases or decreases the reference value of the corresponding reference node when the object is referenced or released; creates a cross-binding item for an object array through the reference manager, increases the cross-reference value of each reference node in the cross-binding item, wherein the object array includes multiple objects with a cross-reference relationship, and the cross-binding item includes reference nodes corresponding to each object in the object array; and 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; and when the reference manager detects that the reference value and cross-reference value of the reference node are both equal to the preset value, the object corresponding to the reference node is deregistered, thereby accurately detecting the unused state of the object.
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 the C language, an object is defined as an area of memory that stores data. This data can be referenced through variable names or pointers. Object management primarily involves the creation, use, maintenance, and destruction of an object. The entire process from creation to destruction is the object's lifecycle, and object management can also be understood as managing the object's lifecycle.

[0003] Reference counting is a commonly used technique in existing technologies for automatically managing the lifecycle of objects. Reference counting tracks the number of times each object is referenced, and when the reference count reaches zero, the object's destruction callback is automatically triggered to release resources. Reference counting works well for handling the lifecycle of a single object. However, when cross-references exist between objects, a simple reference counting mechanism cannot correctly handle the timing of object destruction, resulting in the reference count failing to return to zero, making it impossible to accurately determine the unused state of an object. Consequently, the destruction callback function cannot be triggered when the object is unused, leading to resource leaks and memory usage. 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. When it is detected that the reference value and cross-reference value of the object are both equal to preset values, it is determined that the object is in an unused state, thereby deregistering the object to correctly release memory resources. This solves the problem in the prior art that it is impossible to accurately determine the unused state of an object when there are cross-references between objects, and effectively avoids resource leakage and memory occupation.

[0005] In a first aspect, the present application provides an object reference management method, comprising:

[0006] Creating a reference node for a newly added object through a reference manager, initializing a reference value and a cross-reference value of the reference node for the newly added object, and increasing or decreasing a reference value of a corresponding reference node when the object is referenced or released by the reference manager;

[0007] creating, by a reference manager, a cross-binding item of an object array, and 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 decreasing the cross-reference value of each reference node in the cross-binding item when the reference value of each reference node is equal to a preset value;

[0008] 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.

[0009] In a second aspect, the present application provides an object reference management device, comprising:

[0010] a reference node management module 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 increase or decrease the reference value of the corresponding reference node when the object is referenced or released;

[0011] a cross-binding item management module configured to create a cross-binding item for an object array through a reference manager, and to 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 decreases the cross-reference value of each reference node in the cross-binding item when the reference value of each reference node is equal to a preset value;

[0012] 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.

[0013] In a third aspect, the present application provides an object reference management device, comprising:

[0014] One or more processors; a storage device storing one or more programs, wherein 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.

[0015] 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.

[0016] 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 a reference node for 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 status of the object through the reference value. When the reference manager detects that the reference value of each reference node in a cross-binding item reaches a preset value, it confirms that the reference nodes in the cross-binding item have ended cross-referencing each other, thereby reducing the cross-reference values of each reference node in the cross-binding item and accurately determining 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 an object are both equal to the preset value, it confirms that the object is currently unused, achieving accurate detection of the object's used or unused state. This solves the problem in the prior art of being unable to accurately determine the unused state of an object when cross-references exist between objects, thereby triggering the destruction callback function to destroy the unused object at the right time, effectively avoiding resource leaks and memory occupation. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 This is a flowchart of an object reference management method provided by an embodiment of the present application;

[0018] Figure 2 is a schematic diagram of the internal resources of the reference manager provided in an embodiment of the present application;

[0019] Figure 3 This is a flowchart of triggering a reference manager to perform garbage collection operations according to a reference value provided by an embodiment of the present application;

[0020] Figure 4 This is a flowchart of a reference manager processing junk nodes provided by an embodiment of the present application;

[0021] Figure 5 is a schematic diagram of the management process of the reference manager provided in an embodiment of the present application;

[0022] Figure 6This is a schematic diagram of the structure of an object reference management device provided by an embodiment of the present application;

[0023] Figure 7 This is a structural diagram of an object reference management device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] To further clarify the objectives, technical solutions, and advantages of this application, specific embodiments of the present application are described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are intended only to illustrate this application and are not intended to limit it. It should also be noted that, for ease of description, the drawings only illustrate portions relevant to this application, not all of them. Before discussing the exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts depict the various operations (or steps) as sequential processes, many of the operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process may terminate upon completion of its operations, but may also include additional steps not shown in the accompanying drawings. The process may correspond to a method, function, procedure, subroutine, subprogram, or the like.

[0025] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.

[0026] In existing, relatively similar implementations, objects in the C language are typically represented by structures, with reference counts maintained as member variables of the structure. When an external environment obtains a reference to an object, the reference count increments; when the external environment releases the reference to the object, the reference count decrements. When the reference count reaches 0, the object's destruction callback is automatically triggered to release the object's resources. Traditional reference counting methods perform well when managing the lifecycle of a single object, but the emergence of cross-references complicates object lifecycle management and makes it prone to errors. If references between objects form a closed reference loop, or cross-references (for example, object A references object B, and object B references object A), the reference count will not drop to zero even if the object is no longer referenced by the external environment. This makes it impossible to accurately determine the object's unused state, and consequently, the destruction callback cannot be triggered when the object is unused, resulting in resource leaks and memory usage. To avoid this, programmers often need to implement additional logic to track and manage object reference relationships, which significantly increases code complexity and maintenance difficulties.

[0027] To solve the above problems, this embodiment provides an object reference management method, which manages the reference value and cross-reference value of each object through a reference manager. When it is detected that the reference value and cross-reference value of the object are equal to the preset value, it is determined that the object is in an unused state, and the object is deregistered to correctly release memory resources, effectively avoiding resource leakage and memory occupation.

[0028] The object reference management method provided in this embodiment can be executed by an object reference management device. The object reference management device can be implemented through software and / or hardware. The object reference management device can be composed of two or more physical entities, or a single physical entity. For example, the object reference management device can be a computer or server, which are intelligent terminals with high processing capabilities. The server can be implemented as a standalone server or a server cluster consisting of multiple servers.

[0029] The object reference management device is installed with at least one type of operating system. The object reference management device can install at least one application based on the operating system. 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 one application that can execute the object reference management method.

[0030] 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.

[0031] 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:

[0032] 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.

[0033] 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 with cross-reference relationships. 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.

[0034] Exemplarily, when a new object is created in a certain external environment, a reference node of the new object is created through the 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 as to indicate that the object corresponding to the reference node is a new object through a negative integer, thereby preventing 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 as to indicate that the object corresponding to the reference node has no interactive reference relationship with other objects through zero.

[0035] Optionally, the reference manager stores reference nodes for each object in a node list. After creating a reference node for a newly added object, the reference manager adds the reference node to the node list. Note that if the reference node is a newly added object or is referenced externally, it is stored in the node list. Once a non-newly added object is no longer referenced externally, the corresponding reference node is deleted from the node list as a junk node. This prevents the uncontrolled growth of reference nodes in the node list and improves the management convenience of the reference manager.

[0036] The reference manager provides an initialization interface to initialize the reference manager. Specifically, the reference manager's initialization interface is called 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. Afterwards, the reference manager's mutex lock is initialized so that each subsequent call to the reference manager's interface uses the mutex lock to lock the reference manager's interface. Before exiting the interface, an unlocking operation is performed 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 by 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.

[0037] 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 to 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.

[0038] It should be noted that when the reference manager supports multi-threaded access, the reference manager's interface is locked using 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. Afterwards, after the reference manager creates the reference node for the newly added object, it will feedback the successful node creation to the external environment. After receiving the corresponding feedback, the external environment will unlock the add object interface. After unlocking, the add object interface can be accessed by other external environments.

[0039] After creating a reference node for an object, the reference manager can increase or decrease the reference value of the reference node based on whether the object is referenced or released by the external environment. Optionally, the object's reference value monotonically increases or decreases according to a first preset value, so that the ratio of the reference value of the reference node to the first preset value accurately represents the number of times the object is currently referenced. That is, when the object is first referenced by the external environment, the reference value of the object is increased from a negative integer to the first preset value. Thereafter, the reference value is increased by the first preset value each time the object is referenced by the external environment, and decreased by the first preset value each time the object is released by the external environment. For example, if the object's initial reference value is -1, the object's reference value is increased from -1 to 1 when the object is first referenced by the external environment, and then increased by 1 each time the object is referenced by the external environment, and decreased by 1 each time the object is released by the external environment. The ratio of the reference value of the reference node to the first preset value accurately represents 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 using the initial reference value of -1 and the first preset value of 1 as an example.

[0040] Optionally, the reference manager also provides an add reference interface. Before referencing an object, the external environment can call the reference manager's add reference interface to notify the reference manager that it intends to reference the object, so that the reference manager can increase the reference value of the referenced object's reference node. The specific implementation process is as follows: before referencing an object, the reference manager calls the add reference interface and passes the object pointer of the object as a parameter to the reference manager. The reference manager determines the object's reference node based on the received object pointer and increases the reference value of the corresponding reference node. Exemplarily, before referencing an object, the external environment calls the add reference interface of the reference manager and passes 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. Based on the object pointer, the reference manager searches for the reference node that stores the object pointer and determines the found reference node 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. 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 of successful reference value addition to the external environment through the reference addition interface. After receiving the feedback from the reference manager, the external environment starts to reference the object.

[0041] 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.

[0042] Optionally, the reference manager also provides a reduce reference interface. Before releasing an object, the external environment can call the reduce reference interface of the reference manager to notify the reference manager that it is releasing 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 as follows: before releasing the object, the reference manager calls the reduce reference interface of the reference manager and passes the object pointer of the object to the reference manager. The reference manager determines the object's reference node based on the received object pointer and reduces the reference value of the corresponding reference node. Exemplarily, before releasing an object, the external environment calls the reduce reference interface of the reference manager and passes the object pointer of the object to be released as a parameter to the reference manager. After receiving the object pointer through the reduce reference interface, the reference manager confirms that the object pointed to by the object pointer is about to be released by the external environment. Based on the object pointer, the reference manager searches for the reference node that stores the object pointer, identifies 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 uses the reduce reference interface to feedback information to the external environment indicating that the reference value reduction was successful. After receiving the feedback from the reference manager, the external environment begins to release the object.

[0043] 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 was 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.

[0044] S120. Create a cross-binding item for the object array through the reference manager, and 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. 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.

[0045] For example, when an external environment cross-references multiple objects, an object array may be created based on the multiple cross-referenced objects. A cross-binding item for the object array may be created by a reference manager. When creating the cross-binding item, the reference manager may generate a node array corresponding to the reference nodes of each object in the object array and store it in the cross-binding item. After creating the cross-binding item for 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 indicates the number of groups of objects with which the corresponding object has a cross-reference relationship.

[0046] 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.

[0047] For example, after establishing a cross-reference relationship between 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 can 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 the 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 between 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 the reference manager. Since the corresponding external environment will create corresponding reference nodes in the reference manager when Object A, Object B and Object C are initially created, the reference manager can directly obtain the reference nodes of Object A, Object B and Object 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 Object A, Object B and Object C by 1.

[0048] Of course, an object may not have a cross-reference relationship with other objects. In this 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 will be created in the reference manager for the object and the cross-reference value of the reference node of the object will be increased to 1, indicating that the object currently has a cross-reference relationship with a group of objects.

[0049] refer to Figure 2 When creating a cross-binding item for an object array, the reference manager creates a cross-binding item for the object array in the cross-binding list, places the reference nodes of each object in the object array into a node array, and saves the node array to the cross-binding item. Furthermore, the reference manager counts the number of nodes in the node array and saves the node count to the cross-binding item.

[0050] Optionally, the reference manager also provides a cross-binding interface, which the external environment can call to create a cross-binding entry for an object array in the reference manager. The specific implementation process is as follows: multiple objects with a cross-reference relationship are added to an object array. The reference manager calls the cross-binding interface and passes the object array as a parameter to the reference manager. The reference manager creates a cross-binding entry for the object array, obtains corresponding reference nodes based on each object in the object array, and stores the obtained reference nodes in the cross-binding entry. Exemplarily, after establishing the cross-reference relationship between the multiple objects, the external environment places the multiple objects into an object array, where the objects placed into the object array can be object pointers to the objects. The external environment calls the cross-binding interface of the reference manager and passes the object array as a parameter to the reference manager. The reference manager searches for the corresponding reference node in the node list based on the object pointer in the object array transmitted by the cross-binding interface, places the found reference node into a node array, creates a cross-binding entry for the object array in the cross-binding list, and stores the node array in the cross-binding entry. The cross-reference value of the found reference node is then 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.

[0051] 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 item 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.

[0052] 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. 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. Therefore, 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. In addition, 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.

[0053] For example, suppose the reference nodes of Object A and Object B are stored in cross-binding entry X, and the reference nodes of Object A and Object C are stored in cross-binding entry Y. If both Object A's and Object B's reference values are equal to 0, this indicates that Object A is no longer directly referenced by external 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. In other words, the number of cross-reference relationships between Object B and Object A has been reduced by one. In this case, the cross-reference values of both Object B and Object A are decremented by 1. If Object B only has a cross-reference relationship with Object A, and Object A has cross-reference relationships with Object B and Object C, then Object B's cross-reference value, after decrementing by 1, is equal to 0, indicating that Object B currently has no cross-reference relationship with any object. If Object C's reference value is not equal to 0, this indicates that Object A is indirectly referenced by other external environments through Object C's reference. In other words, Object A is still in use, but its cross-reference value is equal to 1, indicating that Object A currently has a cross-reference relationship with a group of objects. If and only if both the reference value and cross-reference value of an object are equal to the preset value, that is, equal to zero, it is confirmed that the object has no direct or indirect references from 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.

[0054] 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.

[0055] 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 a 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, thereby effectively cleaning up unused objects and avoiding resource leaks and memory occupation. When it is detected that the reference value or cross-reference value of a 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.

[0056] Optionally, the reference value of the reference node will be equal to zero only during the reduction process. In order to reduce the workload of the reference manager, after the reference value of the reference node is reduced, it can be determined whether to trigger the garbage collection operation of the reference manager based on the reference value, so that the cross-reference value of the reference node can be adjusted by 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 This is a flowchart of triggering the reference manager to perform garbage collection operations according to the reference value provided by the 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:

[0057] S1301: The reference manager checks whether the reference value of the reference node is equal to a preset value.

[0058] For example, after decrementing 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 decrement reference interface to decrement the reference value before performing the determination in step S1301. If the reference value is equal to zero, indicating that the object of the reference node is no longer directly referenced by the external environment, the reference manager further determines whether the object of the reference node is indirectly referenced by the external environment.

[0059] S1302. When the reference value of the reference node is equal to the 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.

[0060] 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 objects corresponding to the reference nodes in the cross-binding item no longer have a cross-reference relationship. At this time, the reference manager will reduce the cross-reference value of each reference node in the cross-binding item by 1, and then delete the cross-binding item.

[0061] For example, assuming that the reference nodes of objects A and B are in cross-binding item X, and the reference nodes of objects A and 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 the reference values of the reference nodes of objects A and B in cross-binding item X where object A is located are both equal to zero, and the reference values of the reference nodes of objects A and C in cross-binding item Y where object A is located are both equal to zero. If the reference values of the reference nodes of objects A and B are both equal to zero, the cross-reference values of the reference nodes of objects A and B are both reduced by 1, and cross-binding item X is deleted. 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, the cross-reference values of the reference nodes of objects A and C are not adjusted. 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, the cross-reference values of the reference nodes are reduced by N in total.

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

[0063] 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 determined 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 junk node. When the reference value or cross-reference value of the reference node is not equal to zero, it is determined that the object of the reference node is directly or indirectly referenced by the external environment, and the reference node is not determined to be a junk node.

[0064] 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 value and cross-reference value of each reference node in the node list, thereby determining the reference node whose reference value and cross-reference value are both equal to zero as a garbage node, and then calls the destruction callback function saved by the garbage node to deregister the object of the garbage node.

[0065] It should be noted that when the reference manager supports multi-threaded access, it uses a mutex to lock the garbage collection interface when calling the garbage collection interface, and then unlocks the interface after the garbage collection operation is complete. However, the garbage collection interface is locked when the reference manager performs the garbage collection operation. If the reference manager calls the destruction callback function in the garbage node to deregister the object of the garbage node during the garbage collection operation, the object is locked during deregistration, which means that the object will call the external mutex. However, when the garbage node is discovered, it is within the protection range of the reference manager's internal mutex. External mutex operations are not allowed within this protection range. Because the reference manager serves as a low-level, general functional module, any external lock operation within the reference manager's mutex protection range will cause a deadlock. Therefore, when performing the garbage collection operation, the reference manager only executes the steps until the garbage node is discovered. It does not deregister the garbage node's object. Instead, it waits until the garbage collection interface is unlocked before deregistering the garbage node's object.

[0066] For example, Figure 4 This is a 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 garbage nodes specifically include S1304-S1306:

[0067] S1304: When the reference manager determines that the reference value of the reference node is equal to a preset value, the reference manager uses a mutex lock to lock the garbage collection interface.

[0068] 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.

[0069] 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 nodes whose reference value and cross-reference value are equal to the preset value to the list of nodes to be destroyed.

[0070] 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. 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 certain 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 value and cross-reference value are both equal to zero are added as garbage nodes to the list of nodes to be destroyed.

[0071] 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.

[0072] Exemplarily, after adding all garbage nodes to the list of nodes to be destroyed, the reference manager completes garbage collection and unlocks the garbage collection interface to remove the garbage nodes from the reference manager's mutex lock protection range. Subsequently, the garbage node objects are deregistered based on the destruction callback functions stored by the garbage nodes in the list of nodes to be destroyed. After successfully deregistering the garbage node objects, the corresponding reference nodes are deleted from the reference manager's node list. After deregistering all garbage node objects in the list of nodes to be destroyed, the list of nodes to be destroyed is deleted.

[0073] 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 is described as an example. Figure 5As shown, external environment 1 creates objects A and B, then calls the reference add interface to add them to the reference manager. This causes the reference manager to create a reference node A for object A in the node list, storing the object pointer and object destruction callback function for object A, and a reference node B for object B in the node list, storing the object pointer and object destruction callback function for object B. Subsequently, when objects A and B need to cross-reference, external environment 1 places objects A and B into an object array, calls the cross-binding interface, and passes the object array containing objects A and B as a parameter to the reference manager. The reference manager creates a cross-binding item for the object array to store reference nodes for the objects in the 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 then searches for object A's reference node A and increments the reference value of reference node A by 1. 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 then searches for object B's reference node B and increments the reference value of reference node B by 1. 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 searches for object A's reference node 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 external environment 1 completes its work, it will begin to release previously referenced objects A and 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 searches for object A's reference node A, decrements the reference value of reference node A by 1, 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 decrement reference interface is called to notify the reference manager that object B is being released. The reference manager then searches for object B's reference node B, decrements its reference value by 1, and checks whether its reference value is equal to 0. If this is the case, the reference manager checks whether the reference value of another reference node A in the cross-binding entry containing reference node B is equal to 0. If this value is equal to 1 (external environment 2 still references object A), the cross-reference value between reference nodes A and B is not adjusted. External environment 1 then releases objects A and B and exits the environment.After completing its work, external environment 2 begins releasing the previously referenced object A. Before releasing object A, it calls the reference manager's decrement reference interface to notify the reference manager of the release. The reference manager then locates reference node A for object A, decrements its reference value by 1, releases object A, and exits the environment. The reference manager then checks whether the reference value of reference node A is equal to 0. If so, it checks whether the reference value of another reference node B in the cross-binding entry containing reference node A is equal to 0. If reference node B's reference value is equal to 0, it decrements the cross-reference value of both reference nodes A and B by 1, resulting in both the cross-reference values of reference nodes A and B being equal to 0. The reference and cross-reference values of reference nodes A and B are then checked. If both are equal to 0, the object destruction callback function in reference node A is triggered to destroy object A, and the object destruction callback function in reference node B is triggered to destroy object B. Finally, reference nodes A and B are released from the node list.

[0074] In summary, the object reference management method provided by the embodiment of the present application creates a reference node for 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 the 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 status of the object through the reference value. When the reference manager detects that the reference value of each reference node in a cross-binding item reaches a preset value, it confirms that the reference nodes in the cross-binding item have ended cross-referencing each other, thereby reducing the cross-reference values of each reference node in the cross-binding item and accurately determining 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 an object are both equal to the preset value, it confirms that the object is currently unused, achieving accurate detection of the object's used or unused state. This solves the problem in the prior art of being unable to accurately determine the unused state of an object when cross-references exist between objects, thereby triggering the destruction callback function to destroy the unused object at the right time, effectively avoiding resource leaks and memory occupation.

[0075] Based on the above embodiments, Figure 6 This is a schematic diagram of the structure of an object reference management device provided by 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.

[0076] The reference node management module 21 is configured to create a reference node for 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;

[0077] a cross-binding item management module 22 configured to create a cross-binding item for an object array through a reference manager, and to 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, and the cross-binding item includes a reference node corresponding to each object in the object array, and the reference manager decreases the cross-reference value of each reference node in the cross-binding item when the reference value of each reference node is equal to a preset value;

[0078] 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.

[0079] Based on the above embodiment, the reference node management module 21 includes: a reference node creation unit, which is configured to call the reference manager's add object interface 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.

[0080] 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 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.

[0081] Based on 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 object's reference node based on 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 object's reference node based on the received object pointer and decreases the reference value of the corresponding reference node.

[0082] Based on 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 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; 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.

[0083] 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.

[0084] 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.

[0085] 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 the 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 node 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 status of the object through the reference value. When the reference manager detects that the reference value of each reference node in a cross-binding item reaches a preset value, it confirms that the reference nodes in the cross-binding item have ended cross-referencing each other, thereby reducing the cross-reference values of each reference node in the cross-binding item and accurately determining 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 an object are both equal to the preset value, it confirms that the object is currently unused, achieving accurate detection of the object's used or unused state. This solves the problem in the prior art of being unable to accurately determine the unused state of an object when cross-references exist between objects, thereby triggering the destruction callback function to destroy the unused object at the right time, effectively avoiding resource leaks and memory occupation.

[0086] 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.

[0087] Figure 7 This is a schematic diagram of the structure of an object reference management device provided by 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.

[0088] 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 (e.g., the reference node management module 21, the cross-binding item management module 22, and the object deregistration module 23 in the object reference management device). Memory 32 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data generated based on device usage, etc. Memory 32 may also include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the memory may further include memory remotely located relative to the processor, which can be connected to the device via a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

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

[0090] 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.

[0091] 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.

[0092] 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.

[0093] An embodiment of the present application also provides a storage medium containing computer-executable instructions, which are used to execute an object reference management method when executed by a computer processor. The object reference management method includes: creating a reference node for 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 increasing or decreasing the reference value of the corresponding reference node when the object is referenced or released; creating a cross-binding item for an object array through the reference manager, and increasing the cross-reference value of each reference node in the cross-binding item, wherein the object array includes multiple objects with a cross-reference relationship, and the cross-binding item includes reference nodes for 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.

[0094] 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-ROMs, floppy disks, or tape drives; 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 disks 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 it may be located in a different second computer system that 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 (e.g., in different computer systems connected via a network). The storage medium may store program instructions (e.g., embodied as a computer program) that can be executed by one or more processors.

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

[0096] The object reference management device, object reference management system, storage medium and object reference management equipment 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.

[0097] The above are only preferred embodiments of the present application and the technical principles employed. The present application is not limited to the specific embodiments described herein, and any obvious changes, readjustments, and substitutions that are apparent to those skilled in the art will not depart from the scope of protection of the present application. Therefore, although the present application has been described in detail through the above embodiments, the present application is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of the present application. 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: Calling 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, the reference manager creating a reference node for the newly added object, saving the object pointer and destruction callback function of the corresponding object in the reference node, initializing the reference value and cross-reference value of the reference node of the newly added object, and the reference manager correspondingly increasing or decreasing the reference value of the corresponding reference node when the object is referenced or released; Adding multiple objects having a cross-reference relationship to an object array, calling a cross-binding interface of the reference manager to pass the object array as a parameter to the reference manager, the reference manager creating a cross-binding item of the object array, obtaining a corresponding reference node according to each object in the object array, saving the obtained reference node in the cross-binding item, and increasing the cross-reference value of each reference node in the cross-binding item, wherein the object array includes multiple 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, deregistering the object corresponding to the reference node; 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 based on the received object pointer and increases the reference value of the corresponding reference node.

2. The object reference management method according to claim 1, characterized in that: The method further comprises: 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 based on the received object pointer and reduces the reference value of the corresponding reference node.

3. The object reference management method according to claim 2, 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; 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, 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.

4. 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 calling and an unlocking operation when exiting.

5. The object reference management method according to claim 4, 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 nodes 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 and the list of nodes to be destroyed in the reference manager are deleted.

6. An object reference management device, characterized in that: include: The reference node management module 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, saves the object pointer and destruction callback function of the corresponding object in the reference node, 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. The reference node management module is further configured to call the add reference interface of the reference manager 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 based on the received object pointer and increases the reference value of the corresponding reference node; a cross-binding item management module configured to add a plurality of objects having a cross-reference relationship to an object array, call a cross-binding interface of the reference manager to pass the object array as a parameter to the reference manager, the reference manager creating a cross-binding item for the object array, obtaining a corresponding reference node based on each object in the object array, saving the obtained reference node in the cross-binding item, and 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 reducing 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.

7. 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 according to any one of claims 1 to 5.

8. A storage medium containing computer-executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to execute the object reference management method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Garbage object detecting method and device

    CN103226476A