CN107168764B - Variable recovery method and device - Google Patents
Variable recovery method and device Download PDFInfo
- Publication number
- CN107168764B CN107168764B CN201710432600.9A CN201710432600A CN107168764B CN 107168764 B CN107168764 B CN 107168764B CN 201710432600 A CN201710432600 A CN 201710432600A CN 107168764 B CN107168764 B CN 107168764B
- Authority
- CN
- China
- Prior art keywords
- variable
- recovered
- condition
- program operation
- recovery
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000011084 recovery Methods 0.000 title claims abstract description 51
- 238000000034 method Methods 0.000 title claims abstract description 32
- 238000004064 recycling Methods 0.000 claims abstract description 8
- 238000013461 design Methods 0.000 claims description 7
- 230000007547 defect Effects 0.000 abstract description 9
- 238000007796 conventional method Methods 0.000 abstract description 4
- 238000011161 development Methods 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 230000007246 mechanism Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
- G06F8/4434—Reducing the memory space required by the program code
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a variable recovery method and a device, wherein the method comprises the following steps: when a variable is declared, giving an identifier to the variable, wherein the identifier indicates the condition that the variable is recycled; and in the program operation, when the condition that the variable is recycled is met, recycling the variable and removing the variable from the memory. According to the variable recovery method and device, the variable is given with the identifier, the identifier indicates the condition to be met when the variable is required to be recovered, and the variable is recovered when the condition indicated by the identifier is met in the program operation, so that the variable can be recovered in time, the variable which is not required to be stored in the memory is removed from the memory in time, and the defect that the variable is not recovered in time in the conventional method can be overcome.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a variable recovery method and device.
Background
In the software development process, variables are usually defined to complete the implementation of functions, and the variables are stored in a memory during the operation process. If there is no garbage collection mechanism, the memory will be consumed up and used up with the extension of the running time, which may affect the running of the application program, for example, the browser will be stuck and crashed.
To solve the above problems, each programming language has a unique or common garbage collection mechanism. At present, there are two main ways of recovering variables in a browser-side language, one is mark removal, that is, when a variable is declared, the environment variable where the variable is located is marked, and when the variable leaves the environment, the variable is recovered. And counting the reference, namely tracking and recording the number of times of each value being used, when a variable is declared, and a reference type is assigned to the variable each time, adding one to the reference number of the value, if the value of the variable becomes another one, reducing the reference number of the value by one, and when the reference number of the value becomes zero, recycling the occupied space. However, both recovery modes have the disadvantage of untimely variable recovery.
Disclosure of Invention
The invention aims to provide a variable recovery method and a variable recovery device. The variable can be recovered in time, and the defects of the prior art are overcome.
In order to achieve the purpose, the invention provides the following technical scheme:
a variable recovery method comprising:
when a variable is declared, giving an identifier to the variable, wherein the identifier indicates the condition that the variable is recycled;
and in the program operation, when the condition that the variable is recycled is met, recycling the variable and removing the variable from the memory.
Optionally, the condition that the variable is recovered is a time when the variable is recovered;
the recovering the variable when the condition that the variable is recovered is met in the program operation comprises the following steps:
and in the program operation, when the time indicated by the identification is reached, recovering the variable.
Optionally, the condition that the variable is recycled is that the variable is referred to at a preset position;
the recovering the variable when the condition that the variable is recovered is met in the program operation comprises the following steps:
and in the program operation, after the variable is referred at the preset position, recycling the variable.
Optionally, before said declaring a variable, assigning an identifier to the variable, the method further includes:
designing, for the variable, the identification indicating a condition under which the variable is reclaimed, in accordance with the variable.
Optionally, the program is a browser application.
A variable recovery device comprising:
the identification module is used for endowing an identification to the variable when the variable is declared, and the identification indicates the condition that the variable is recycled;
and the recovery module is used for recovering the variable and removing the variable from the memory when the condition that the variable is recovered is met in the program operation.
Optionally, the condition that the variable is recovered is a time when the variable is recovered;
the recovery module is used for recovering the variable when the condition that the variable is recovered is met in the program operation, and the recovery module comprises:
the recovery module is specifically configured to recover the variable when the time indicated by the identifier is reached during program operation.
Optionally, the condition that the variable is recycled is that the variable is referred to at a preset position;
the recovery module is used for recovering the variable when the condition that the variable is recovered is met in the program operation, and the recovery module comprises:
the recovery module is specifically configured to recover the variable after the variable is referred to in the preset position during program operation.
Optionally, the system further includes a design module, configured to design, according to the variable, an identifier for indicating a condition that the variable is recycled, before the identifier is assigned to the variable when the variable is declared.
Optionally, the program is a browser application.
According to the technical scheme, the variable recovery method and the variable recovery device provided by the invention have the advantages that the variable is endowed with the identifier when the variable is declared, the identifier indicates the condition that the variable is recovered, and in the program operation process, when the condition that the variable is recovered is met, the variable is recovered and removed from the memory. The variable recovery method and the device can recover the variable in time and overcome the defect that the variable recovery is not timely in the conventional method.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flow chart of a method for recovering variables according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a variable recovery apparatus according to an embodiment of the present invention.
Detailed Description
In order to make those skilled in the art better understand the technical solution of the present invention, the technical solution in the embodiment of the present invention will be clearly and completely described below with reference to the drawings in the embodiment of the present invention, and it is obvious that the described embodiment is only a part of the embodiment of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a method for recovering variables provided in the embodiment of the present invention includes the following steps:
s10: when a variable is declared, an identification is given to the variable, the identification indicating a condition under which the variable is reclaimed.
In software development, when a variable is declared, the variable is given a flag indicating the condition that the variable should satisfy when it should be recovered, according to the actual condition of the variable.
In one embodiment, the condition that the variable is recycled is the time when the variable is recycled, that is, at which time in the program running, the variable is referred to and is not used any more, and the variable can be recycled. In this case, the variable may be given a flag indicating the time at which the variable is recovered according to the actual condition of the variable.
In another embodiment, the condition that the variable is recycled is that the variable is referenced at a preset position, that is, after the variable is referenced at a position in the program running, the variable is not used any more and can be recycled. In this case, the variable may be given a flag according to the actual condition of the variable, and the flag indicates that the variable may be recovered after being referred to by the preset position.
In addition, before step S10, the method further includes step S13: designing, for the variable, the identification indicating a condition under which the variable is reclaimed, in accordance with the variable.
Before declaring a variable, designing an identifier for the variable according to the actual condition of the variable, and determining the condition which the variable should meet when being recycled. In both embodiments, a flag is designed for the variable, and the flag indicates the time or the position of the variable to be recovered.
S11: and in the program operation, when the condition that the variable is recycled is met, recycling the variable and removing the variable from the memory.
And in the program operation, the variable is referred to for multiple times, and when the condition that the variable indicated by the identification is recycled is met, the variable is recycled and removed from the memory, so that the memory is released. The variable can no longer be used unless re-declared again.
The condition that the variable is recovered may be a time when the variable is recovered, in this way, the step specifically includes: and in the program operation, when the time indicated by the identification is reached, recovering the variable.
Therefore, in the variable recovery method of the embodiment, the identifier is given to the variable to indicate the time for recovering the variable, and the variable is recovered when the time indicated by the identifier is reached in the program operation, so that the variable can be recovered in time, the variable which does not need to be stored in the memory can be removed from the memory in time, and the defect that the variable is not recovered in time in the conventional method can be overcome.
Alternatively, the condition that the variable is recovered may be that the variable is referenced at a preset position. Correspondingly, in this way, the steps specifically include: and in the program operation, after the variable is referred at the preset position, recycling the variable.
Therefore, in the variable recovery method of the embodiment, the identifier is given to the variable, the identifier indicates that the variable should be recovered after being referred by the preset position, and the variable is recovered after being referred by the identifier in the program operation process, so that the variable can be recovered in time, the variable which does not need to be stored in the memory can be removed from the memory in time, and the defect that the variable recovery is not timely in the existing method can be overcome.
The variable recovery method can recover the variables in time and remove the variables which are not needed to be stored in the memory from the memory in time, can overcome the defect that the variable recovery is not timely in the existing method, avoids the phenomena of memory overflow, memory shortage and the like, and is beneficial to improving the memory utilization rate and the system operation speed.
The variable recovery method can be applied to the development of browser programs, or can also be applied to the development of other application programs.
Accordingly, referring to fig. 2, an embodiment of the present invention further provides a variable recovery apparatus, including:
an identification module 20, configured to, when a variable is declared, assign an identification to the variable, where the identification indicates a condition under which the variable is recycled;
and the recovery module 21 is configured to recover the variable and remove the variable from the memory when the condition that the variable is recovered is met during program running.
It can be seen that, in the variable recovery apparatus of this embodiment, when a variable is declared, a flag is given to the variable, where the flag indicates a condition that the variable is recovered, and in program operation, when the condition that the variable is recovered is satisfied, the variable is recovered and removed from the memory. The variable recovery device can recover the variable in time and overcome the defect that the variable is not recovered in time by the conventional method.
In one embodiment, the condition that the variable is recycled is the time when the variable is recycled, that is, at which time in the program running, the variable is referred to and is not used any more, and the variable can be recycled. In this case, the variable may be given a flag indicating the time at which the variable is recovered according to the actual condition of the variable.
Correspondingly, the recovery module 21 is specifically configured to recover the variable when the time indicated by the identifier is reached in the program running.
Therefore, in the variable recovery device of the embodiment, the identifier is given to the variable to indicate the time for recovering the variable, and the variable is recovered when the time indicated by the identifier is reached in the program operation, so that the variable can be recovered in time, the variable which does not need to be stored in the memory can be removed from the memory in time, and the defect that the variable is not recovered in time in the existing method can be overcome.
In another embodiment, the condition that the variable is recycled is that the variable is referenced at a preset position, that is, after the variable is referenced at a position in the program running, the variable is not used any more and can be recycled. In this case, the variable may be given a flag according to the actual condition of the variable, and the flag indicates that the variable may be recovered after being referred to by the preset position.
Correspondingly, the recovery module 21 is specifically configured to recover the variable after the variable is referred to in the preset position during program running.
Therefore, in the variable recovery device of the embodiment, by giving the identifier to the variable, the identifier indicates that the variable should be recovered after being referred by the preset position, and in the program operation, after the variable is referred by the identifier indicating position, the variable is recovered, so that the variable can be recovered in time, the variable which does not need to be stored in the memory is removed from the memory in time, and the defect that the variable is not recovered in time in the existing method can be overcome.
Further, the variable recovery apparatus of this embodiment further includes a design module, configured to design, for a variable, an identifier indicating a condition under which the variable is recovered according to the variable before the variable is given an identifier when the variable is declared.
Before declaring a variable, according to the actual condition of the variable, designing an identifier for the variable through a design module, and determining the condition which the variable should meet when being recycled. In both embodiments, a flag is designed for the variable, and the flag indicates the time or the position of the variable to be recovered.
The variable recovery device of the embodiment can be applied to the development of browser programs, or can also be applied to the development of other application programs.
The above description details a method and apparatus for recovering variables provided by the present invention. The principles and embodiments of the present invention are explained herein using specific examples, which are presented only to assist in understanding the method and its core concepts. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.
Claims (8)
1. A method for recovering variables, applied to a browser, includes:
when a variable is declared, giving an identifier to the variable, wherein the identifier indicates the condition that the variable is recycled;
in the program operation, when the condition that the variable is recycled is met, recycling the variable and removing the variable from the memory;
the condition that the variable is recovered is the moment when the variable is recovered; the recovering the variable when the condition that the variable is recovered is met in the program operation comprises the following steps: and in the program operation, when the time indicated by the identification is reached, recovering the variable.
2. The variable recovery method according to claim 1, wherein the condition that the variable is recovered is that the variable is referenced at a preset position;
the recovering the variable when the condition that the variable is recovered is met in the program operation comprises the following steps:
and in the program operation, after the variable is referred at the preset position, recycling the variable.
3. The variable reclamation method as recited in any of claims 1-2, wherein the step of, when declaring a variable, identifying the variable further comprises:
designing, for the variable, the identification indicating a condition under which the variable is reclaimed, in accordance with the variable.
4. The variable reclamation method as recited in any one of claims 1-2, wherein the program is a browser application.
5. A variable recovery device, applied to a browser, comprises:
the identification module is used for endowing an identification to the variable when the variable is declared, and the identification indicates the condition that the variable is recycled;
the recovery module is used for recovering the variable and removing the variable from the memory when the condition that the variable is recovered is met in the program operation;
the condition that the variable is recovered is the moment when the variable is recovered; the recovery module is used for recovering the variable when the condition that the variable is recovered is met in the program operation, and the recovery module comprises: the recovery module is specifically configured to recover the variable when the time indicated by the identifier is reached during program operation.
6. The variable recovery apparatus according to claim 5, wherein the condition that the variable is recovered is that the variable is referenced at a preset position;
the recovery module is used for recovering the variable when the condition that the variable is recovered is met in the program operation, and the recovery module comprises:
the recovery module is specifically configured to recover the variable after the variable is referred to in the preset position during program operation.
7. The variable recovery apparatus according to any one of claims 5 to 6, further comprising a design module configured to design, for a variable, the identifier indicating a condition under which the variable is recovered, based on the variable, before assigning the identifier to the variable when declaring the variable.
8. The variable recovery apparatus according to any one of claims 5 to 6, wherein the program is a browser application program.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710432600.9A CN107168764B (en) | 2017-06-09 | 2017-06-09 | Variable recovery method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710432600.9A CN107168764B (en) | 2017-06-09 | 2017-06-09 | Variable recovery method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107168764A CN107168764A (en) | 2017-09-15 |
CN107168764B true CN107168764B (en) | 2021-06-11 |
Family
ID=59825958
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710432600.9A Active CN107168764B (en) | 2017-06-09 | 2017-06-09 | Variable recovery method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107168764B (en) |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101046755B (en) * | 2006-03-28 | 2011-06-15 | 郭明南 | System and method of computer automatic memory management |
EP2144163A1 (en) * | 2008-07-09 | 2010-01-13 | Software AG | Method and system for synchronizing the execution of a critical code section |
CN105404589B (en) * | 2015-10-29 | 2019-04-30 | 天脉聚源(北京)教育科技有限公司 | A kind of rubbish recovering method and device |
-
2017
- 2017-06-09 CN CN201710432600.9A patent/CN107168764B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN107168764A (en) | 2017-09-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108459898B (en) | Resource recovery method and device | |
CN107229414B (en) | Storage space recovery method and device | |
CN101699476B (en) | Data processing method and device of smart cards | |
CN104503828A (en) | Process management method and terminal | |
CN104021043A (en) | Interruption reentry method and system of batch applications | |
CN106649132A (en) | Solid-state drive junk recovery method | |
CN110647318B (en) | Method, device, equipment and medium for creating instance of stateful application | |
CN109144428B (en) | Garbage recycling method, device and medium applied to solid state disk | |
CN111045712A (en) | Single system upgrading method and system with backup function | |
CN102521530A (en) | License recycling method and system | |
CN107168764B (en) | Variable recovery method and device | |
CN104407899A (en) | Method for restoring and starting network card after MAC address is changed under REDHAT operating system | |
CN107912063B (en) | Memory recovery method and device | |
CN111831639B (en) | Global unique ID generation method and device and vehicle management system | |
CN102799835B (en) | The anti-regeneration method of plug-in unit and the corresponding anti-regeneration system of plug-in unit | |
CN112035253B (en) | Linux system page cache recovery method and related device | |
CN106383510B (en) | The differentiation and processing method of control system accident power-off | |
CN105278987B (en) | A kind of information processing method and electronic equipment | |
CN110858178A (en) | Memory recovery method, device, equipment and medium | |
CN103716696A (en) | System software upgrading method and smart television | |
CN105404589A (en) | Garbage collection method and apparatus | |
CN113900743A (en) | Java object access method and device | |
CN103412828A (en) | Data processing method and device | |
CN112463374A (en) | Memory management method, device, equipment and storage medium | |
CN109558332B (en) | Object recovery method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |