# US 2022/0012085 A1 · Memory management method and apparatus

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2022/0012085 A1
- Document ID: US20220012085A1
- Status: Published application
- Kind: A1
- Application number: 17/483,953
- Filed: 2021-09-24
- Published: 2022-01-13
- Earliest claimed: 2019-03-25
- Assignees: Huawei Technologies Co., Ltd.
- Applicants: Huawei Technologies Co., Ltd.
- Inventors: Hui SHI; Yang DING; Kui ZHANG; Chengyuan WANG; Chao WANG
- Web page: https://patentgrep.com/patent/US20220012085A1

## CPC

- G06F 9/4488: {Object-oriented}
- G06F 9/45558: {Hypervisor-specific management and integration aspects}
- G06F 9/45533: {Hypervisors; Virtual machine monitors}
- G06F 9/5016: {the resource being the memory}
- G06F 9/5022: {Mechanisms to release resources}
- G06F 12/0238: {Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory}
- G06F 12/0253: {Garbage collection, i.e. reclamation of unreferenced memory}
- G06F 12/0261: {using reference counting}
- G06F 2009/45583: {Memory management, e.g. access or allocation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The technology of this application relates to a memory management method and apparatus. When garbage collection is performed by using the method, stored information about a first reference cycle is first obtained, where the first reference cycle is a cyclic reference formed by a plurality of objects, and the information about the first reference cycle includes the plurality of objects in the first reference cycle and a reference relationship between the plurality of objects. The method further includes determining that a second reference cycle exists, where information about the second reference cycle matches the information about the first reference cycle, and the information about the second reference cycle includes a plurality of objects in the second reference cycle and a reference relationship between the plurality of objects. The method further includes reclaiming memory occupied by the plurality of objects in the second reference cycle.

## Claims

### Claim 1

A memory management method, comprising:
obtaining stored information about a first reference cycle, wherein the first reference cycle is includes a cyclic reference formed by a plurality of objects, and the information about the first reference cycle comprises the plurality of objects in the first reference cycle and a reference relationship between the plurality of objects;
determining that a second reference cycle exists, wherein information about the second reference cycle matches the information about the first reference cycle, and the information about the second reference cycle comprises a plurality of objects in the second reference cycle and a reference relationship between the plurality of objects; and
reclaiming memory occupied by the plurality of objects in the second reference cycle.

### Claim 2 (depends on 1)

The method according to claim 1, wherein
the information about the first reference cycle further comprises a reference counting value, in the first reference cycle, of each object in the first reference cycle, and
the information about the second reference cycle further comprises a reference counting value, in the second reference cycle, of each object in the second reference cycle; and
the information about the second reference cycle matching the information about the first reference cycle comprises the plurality of objects in the second reference cycle are in a one-to-one correspondence with the plurality of objects in the first reference cycle and the reference counting value of each object in the second reference cycle is equal to a reference counting value of a corresponding object in the first reference cycle.

### Claim 3 (depends on 1)

The method according to claim 1, wherein the information about the first reference cycle comprises an identifier of a referenced object, and the identifier of the referenced object includes a storage address of the referenced object, an offset of a storage address of the referenced object relative to a storage address of a referencing object of the referenced object, or a name of the referenced object.

### Claim 4 (depends on 1)

The method according to claim 1, wherein the information about the first reference cycle is stored in metadata of a first object, the first object is a last object in the plurality of objects in the first reference cycle and the last object is released by an external object, and the external object is an object, other than the plurality of objects in the first reference cycle, that references the first object.

### Claim 5 (depends on 1)

The method according to claim 1, wherein before obtaining the stored information about the first reference cycle, the method further comprises:
obtaining a plurality of objects generated in a running process of an application program, wherein any one of the plurality of objects is an object whose reference counting value is greater than 0;
determining a reference relationship between the plurality of objects based on information about each of the plurality of objects, wherein the information about each object comprises an identifier of an object referenced by each object; and
generating and storing the information about the first reference cycle based on the reference relationship between the plurality of objects.

### Claim 6 (depends on 1)

The method according to claim 1, further comprising:
determining that a reference counting value of any object is less than or equal to a first threshold, and triggering the obtaining the stored information about the first reference cycle, wherein the any object is included in the first reference cycle.

### Claim 7 (depends on 6)

The method according to claim 6, wherein the any object is a last object in the plurality of objects in the first reference cycle and the last object is released by an external object, and the external object is an object, other than the plurality of objects in the first reference cycle, that references the first object.

### Claim 8

A non-transitory computer storage medium having computer-executable instructions that, when executed by a computer of a terminal, cause the terminal to provide execution comprising:
obtaining stored information about a first reference cycle, wherein the first reference cycle is includes a cyclic reference formed by a plurality of objects, and the information about the first reference cycle comprises the plurality of objects in the first reference cycle and a reference relationship between the plurality of objects;
determining that a second reference cycle exists, wherein information about the second reference cycle matches the information about the first reference cycle, and the information about the second reference cycle comprises a plurality of objects in the second reference cycle and a reference relationship between the plurality of objects; and
reclaiming memory occupied by the plurality of objects in the second reference cycle.

### Claim 9 (depends on 8)

The non-transitory computer readable storage medium according to claim 8, wherein
the information about the first reference cycle further comprises a reference counting value, in the first reference cycle, of each object in the first reference cycle, and
the information about the second reference cycle further comprises a reference counting value, in the second reference cycle, of each object in the second reference cycle; and
the information about the second reference cycle matching the information about the first reference cycle comprises the plurality of objects in the second reference cycle are in a one-to-one correspondence with the plurality of objects in the first reference cycle and the reference counting value of each object in the second reference cycle is equal to a reference counting value of a corresponding object in the first reference cycle.

### Claim 10 (depends on 8)

The non-transitory computer readable storage medium according to claim 8, wherein the information about the first reference cycle comprises an identifier of a referenced object, and the identifier of the referenced object includes a storage address of the referenced object, an offset of a storage address of the referenced object relative to a storage address of a referencing object of the referenced object, or a name of the referenced object.

### Claim 11 (depends on 8)

The non-transitory computer readable storage medium according to claim 8, wherein the information about the first reference cycle is stored in metadata of a first object, the first object is a last object in the plurality of objects in the first reference cycle and the last object is released by an external object, and the external object is an object, other than the plurality of objects in the first reference cycle, that references the first object.

### Claim 12 (depends on 8)

The non-transitory computer readable storage medium according to claim 8, wherein before obtaining the stored information about the first reference cycle, the terminal is further caused to provide execution comprising:
obtaining a plurality of objects generated in a running process of an application program, wherein any one of the plurality of objects is an object whose reference counting value is greater than 0;
determining a reference relationship between the plurality of objects based on information about each of the plurality of objects, wherein the information about each object comprises an identifier of an object referenced by each object; and
generating and storing the information about the first reference cycle based on the reference relationship between the plurality of objects.

### Claim 13 (depends on 8)

The non-transitory computer readable storage medium according to claim 8, wherein the terminal is further caused to provide execution comprising:
determining that a reference counting value of any object is less than or equal to a first threshold, and triggering the obtaining the stored information about the first reference cycle, wherein the any object is included in the first reference cycle.

### Claim 14 (depends on 8)

The non-transitory computer readable storage medium according to claim 8, wherein the any object is a last object in the plurality of objects in the first reference cycle and the last object is released by an external object, and the external object is an object, other than the plurality of objects in the first reference cycle, that references the first object.

### Claim 15

An apparatus configured for memory management, the apparatus comprising:
a processor; and
a memory configured to store computer readable instructions that, when executed by the processor, cause the apparatus to:
obtain stored information about a first reference cycle, wherein the first reference cycle includes a cyclic reference formed by a plurality of objects, and the information about the first reference cycle comprises the plurality of objects in the first reference cycle and a reference relationship between the plurality of objects;
determine that a second reference cycle exists, wherein information about the second reference cycle matches the information about the first reference cycle, and the information about the second reference cycle comprises a plurality of objects in the second reference cycle and a reference relationship between the plurality of objects; and
reclaim memory occupied by the plurality of objects in the second reference cycle.

### Claim 16 (depends on 15)

The apparatus according to claim 15, wherein
the information about the first reference cycle further comprises a reference counting value, in the first reference cycle, of each object in the first reference cycle, and
the information about the second reference cycle further comprises a reference counting value, in the second reference cycle, of each object in the second reference cycle; and
the information about the second reference cycle matching the information about the first reference cycle comprises the plurality of objects in the second reference cycle are in a one-to-one correspondence with the plurality of objects in the first reference cycle and the reference counting value of each object in the second reference cycle is equal to a reference counting value of a corresponding object in the first reference cycle.

### Claim 17 (depends on 15)

The apparatus according to claim 15, wherein the information about the first reference cycle comprises an identifier of a referenced object, and the identifier of the referenced object includes a storage address of the referenced object, an offset of a storage address of the referenced object relative to a storage address of a referencing object of the referenced object, or a name of the referenced object.

### Claim 18 (depends on 15)

The apparatus according to claim 15, wherein the information about the first reference cycle is stored in metadata of a first object, the first object is a last object in the plurality of objects in the first reference cycle and the last object is released by an external object, and the external object is an object, other than the plurality of objects in the first reference cycle, that references the first object.

### Claim 19 (depends on 15)

The apparatus according to claim 15, wherein the apparatus is further caused to:
determine that a reference counting value of any object is less than or equal to a first threshold, and trigger the obtaining the stored information about the first reference cycle, wherein the any object is included in the first reference cycle.

### Claim 20 (depends on 15)

The apparatus according to claim 15, wherein the any object is a last object in the plurality of objects in the first reference cycle and the last object is released by an external object, and the external object is an object, other than the plurality of objects in the first reference cycle, that references the first object.
