Disclosure of Invention
In view of this, the embodiments of the present disclosure provide a method, an apparatus, and an electronic device for playing data, so as to solve the following problems in the prior art: the advertisement terminal will gradually increase the usage amount of the system memory with each time of loading the advertisement data, and the dynamically allocated heap memory is not released or can not be released due to system reasons, which causes waste of the system memory and also causes serious consequences such as slow program running speed and even system crash.
In one aspect, an embodiment of the present disclosure provides a method for playing data, including: detecting whether the current running memory value of the system reaches a preset threshold value according to a preset time interval; under the condition that the current running memory value reaches the preset threshold value, starting a second process to play first preset data, and closing the first process to release the memory; and after the memory release is finished, starting the first process to play second preset data, and closing the second process.
In some embodiments, before detecting whether the current operating memory value of the system reaches the predetermined threshold at the predetermined time interval, the method further includes: the first process is started to play third predetermined data.
In some embodiments, the initiating the second process to play the first predetermined data comprises: and when the first process finishes playing the third preset data, starting the second process to play the first preset data.
In some embodiments, after detecting whether the current operating memory value of the system reaches the predetermined threshold value at the predetermined time interval, the method further includes: and under the condition that the current running memory value does not reach the preset threshold value, continuously playing the third preset data through the first process.
In some embodiments, the predetermined threshold is less than a memory maximum.
On the other hand, an embodiment of the present disclosure provides an apparatus for playing data, including: the detection module is used for detecting whether the current running memory value of the system reaches a preset threshold value according to a preset time interval; the first execution module is used for starting a second process to play first preset data and closing the first process to release the memory under the condition that the current running memory value reaches the preset threshold value; and the second execution module is used for starting the first process to play second preset data and closing the second process after the memory release is finished.
In some embodiments, further comprising: and the third execution module is used for starting the first process to play third preset data.
In some embodiments, the first executing module is specifically configured to start the second process to play the first predetermined data when the first process finishes playing the third predetermined data.
In some embodiments, the third execution module is further configured to continue to play the third predetermined data through the first process when the current running memory value does not reach the predetermined threshold.
In another aspect, an embodiment of the present disclosure provides an electronic device, which at least includes a memory and a processor, where the memory stores a computer program thereon, and the processor implements the steps of the method when executing the computer program on the memory.
The method and the device for playing the advertisement data have the advantages that the two processes are set in the application program of the advertisement terminal, after the first process is operated, whether the current operation memory value of the system reaches the preset threshold value or not is detected according to the preset time interval, once the preset threshold value is reached, the advertisement data are continuously played through the second process, the first process is closed to release the memory, and after the memory release is completed, the first process is reused to play the advertisement data. The method and the device have the advantages that the process memory detection logic is added, the memory is timely detected, the memory is released in advance before exceeding the standard, the problems of application program flash back and advertisement blank screen playing for a long time in the advertisement terminal are solved, the process that the first process stops playing advertisement data to release the memory is shielded by starting the second process to play the advertisement, the playing effect is improved, and the product performance is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described below clearly and completely with reference to the accompanying drawings of the embodiments of the present disclosure. It is to be understood that the described embodiments are only a few embodiments of the present disclosure, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the described embodiments of the disclosure without any inventive step, are within the scope of protection of the disclosure.
Unless otherwise defined, technical or scientific terms used herein shall have the ordinary meaning as understood by one of ordinary skill in the art to which this disclosure belongs. The use of "first," "second," and similar terms in this disclosure is not intended to indicate any order, quantity, or importance, but rather is used to distinguish one element from another. The word "comprising" or "comprises", and the like, means that the element or item listed before the word covers the element or item listed after the word and its equivalents, but does not exclude other elements or items. The terms "connected" or "coupled" and the like are not restricted to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "upper", "lower", "left", "right", and the like are used merely to indicate relative positional relationships, and when the absolute position of the object being described is changed, the relative positional relationships may also be changed accordingly.
To maintain the following description of the embodiments of the present disclosure clear and concise, a detailed description of known functions and known components have been omitted from the present disclosure.
A first embodiment of the present disclosure provides a method for playing data, where the flow of the method is shown in fig. 1, and the method includes steps S101 to S103:
s101, detecting whether the current operation memory value of the system reaches a preset threshold value according to a preset time interval.
The advertisement terminal is usually implemented by running an APP (application program), that is, the advertisement terminal plays advertisement data using a predetermined APP, so that it must start a process of the predetermined APP when the predetermined APP starts to run, the process is a first process in this embodiment, that is, a main process in which the predetermined APP runs, and when the predetermined APP runs, the first process is started to play third predetermined data.
The third predetermined data may be calculated from when the predetermined APP starts playing until it is determined that the current running memory value reaches the predetermined threshold, that is, the complete advertisement data in the process, for example, when it is determined that the current running memory value reaches the predetermined threshold, 120 advertisement data have been played and 121 th advertisement data are being played, the 121 th advertisement data is a video advertisement, at this time, the video advertisement has been played for 3 seconds, and is not played for 7 seconds, and after the advertisement data that have not been played for 7 seconds are all played, the third predetermined data (i.e., the first 121 advertisement data) is formed. Of course, the third predetermined data may also be based on a time when the current running memory value reaches the predetermined threshold, that is, in the process, in order to ensure that the viewer has the best use experience, the second process may be started after the advertisement data is played once.
In order to ensure that no bad user experience such as program flash back occurs before the third predetermined data is played, when the predetermined threshold is set, the predetermined threshold needs to be smaller than the maximum memory value, so as to ensure that even if the second process is not started immediately, there is enough memory to run the advertisement data of the first process. For example, when the maximum memory value of the system is 2G, the predetermined threshold may be set to 1G or 1.5G, and the like, which may be set by a person skilled in the art according to actual requirements.
S102, when the current running memory value reaches a preset threshold value, a second process is started to play the first preset data, and the first process is closed to release the memory.
In order to ensure the highest response speed of the system, it is preferable that the second process is restarted to play the first predetermined data when the first process finishes playing the third predetermined data.
In concrete implementation, if the current running memory value does not reach the preset threshold value, the third preset data is continuously played through the first process.
S103, after the memory release is finished, the first process is started to play the second preset data, and the second process is closed.
After the memory is released, the memory may be completely released, or the memory may be released until the current running memory value is smaller than a threshold value, where the threshold value needs to ensure that the first process has enough memory to run when set, and may be set to be lower, for example, when the maximum memory value of the system is 2G, the threshold value may be set to 0.2G.
The method and the device for playing the advertisement data have the advantages that the two processes are set in the application program of the advertisement terminal, after the first process is operated, whether the current operation memory value of the system reaches the preset threshold value or not is detected according to the preset time interval, once the preset threshold value is reached, the advertisement data are continuously played through the second process, the first process is closed to release the memory, and after the memory release is completed, the first process is reused to play the advertisement data. The method and the device have the advantages that the process memory detection logic is added, the memory is timely detected, the memory is released in advance before exceeding the standard, the problems of application program flash back and advertisement blank screen playing for a long time in the advertisement terminal are solved, the process that the first process stops playing advertisement data to release the memory is shielded by starting the second process to play the advertisement, the playing effect is improved, and the product performance is improved.
The process of detecting whether the current running memory value of the system reaches the preset threshold value according to the preset time interval can be realized in a first process, namely, a thread is arranged in the first process, when the first process plays advertisement data through Webview, the detection threads work simultaneously, namely, the detection threads are started to execute the detection threads after the first process is started; once the maximum value of the current memory of the system is detected to reach a preset threshold value, a second process is started to play advertisement data, and a first process is closed; then, detecting the current running memory value of the system again, once the memory release is determined to be finished, starting the first process, and closing the second process so as to play the advertisement data by using the first process; and if the current maximum memory value of the system is not detected to reach the preset threshold value, continuing to play the advertisement data by using the first process.
A second embodiment of the present disclosure provides an apparatus for playing data, the apparatus having a structure as shown in fig. 2, and including:
the detection module 10 is configured to detect whether a current operating memory value of the system reaches a predetermined threshold value according to a predetermined time interval; a first executing module 20, coupled to the detecting module 10, configured to start a second process to play the first predetermined data and close the first process to release the memory when the current running memory value reaches a predetermined threshold; the second execution module 30 is coupled to the first execution module 20, and configured to start the first process to play the second predetermined data and close the second process after the memory release is completed.
The advertisement terminal is usually implemented by running an APP (application program), that is, the advertisement terminal plays advertisement data using a predetermined APP, so that it must start a process of the predetermined APP when the predetermined APP starts to run, the process is a first process in this embodiment, that is, a main process in which the predetermined APP runs, and when the predetermined APP runs, the first process is started to play third predetermined data. Therefore, the apparatus for playing data according to the embodiment of the present disclosure may further include a third executing module, coupled to the detecting module, for starting the first process to play the third predetermined data.
The third predetermined data may be calculated from when the predetermined APP starts playing until it is determined that the current running memory value reaches the predetermined threshold, that is, the complete advertisement data in the process, for example, when it is determined that the current running memory value reaches the predetermined threshold, 120 advertisement data have been played and 121 th advertisement data are being played, the 121 th advertisement data is a video advertisement, at this time, the video advertisement has been played for 3 seconds, and is not played for 7 seconds, and after the advertisement data that have not been played for 7 seconds are all played, the third predetermined data (i.e., the first 121 advertisement data) is formed. Of course, the third predetermined data may also be based on a time when the current running memory value reaches the predetermined threshold, that is, in the process, in order to ensure that the viewer has the best use experience, the second process may be started after the advertisement data is played once.
In order to ensure that no bad user experience such as program flash back occurs before the third predetermined data is played, when the predetermined threshold is set, the predetermined threshold needs to be smaller than the maximum memory value, so as to ensure that even if the second process is not started immediately, there is enough memory to run the advertisement data of the first process. For example, when the maximum memory value of the system is 2G, the predetermined threshold may be set to 1G or 1.5G, and the like, which may be set by a person skilled in the art according to actual requirements.
The third execution module is further configured to continue to play the third predetermined data through the first process when the current running memory value does not reach the predetermined threshold value.
In order to ensure that the system response speed is highest, the first execution module is specifically configured to start the second process to play the first predetermined data when the first process finishes playing the third predetermined data.
After the memory is released, the memory may be completely released, or the memory may be released until the current running memory value is smaller than a threshold value, where the threshold value needs to ensure that the first process has enough memory to run when set, and may be set to be lower, for example, when the maximum memory value of the system is 2G, the threshold value may be set to 0.2G.
The method and the device for playing the advertisement data have the advantages that the two processes are set in the application program of the advertisement terminal, after the first process is operated, whether the current operation memory value of the system reaches the preset threshold value or not is detected according to the preset time interval, once the preset threshold value is reached, the advertisement data are continuously played through the second process, the first process is closed to release the memory, and after the memory release is completed, the first process is reused to play the advertisement data. The method and the device have the advantages that the process memory detection logic is added, the memory is timely detected, the memory is released in advance before exceeding the standard, the problems of application program flash back and advertisement blank screen playing for a long time in the advertisement terminal are solved, the process that the first process stops playing advertisement data to release the memory is shielded by starting the second process to play the advertisement, the playing effect is improved, and the product performance is improved.
A third embodiment of the present disclosure provides an electronic device, a structural schematic of which is shown in fig. 3, and the electronic device at least includes a memory 901 and a processor 902, the memory stores a computer program, and the processor implements the method provided in any embodiment of the present disclosure when executing the computer program on the memory, and the method includes the following steps S11 to S13:
s11, detecting whether the current operation memory value of the system reaches a preset threshold value according to a preset time interval;
s12, when the current operation memory value reaches the preset threshold value, starting the second process to play the first preset data, and closing the first process to release the memory;
s13, after the memory release is completed, the first process is started to play the second predetermined data, and the second process is closed.
Before executing the computer program on the storage for detecting whether the current running memory value of the system reaches the preset threshold value according to the preset time interval, the processor also executes the following steps: the first process is initiated to play the third predetermined data.
When the processor executes the computer program which starts the second process on the memory to play the first preset data, the following steps are specifically executed: and starting the second process to play the first preset data when the first process finishes playing the third preset data.
After the processor executes the computer program which detects whether the current running memory value of the system reaches the preset threshold value according to the preset time interval on the storage, the following steps are also executed: and under the condition that the current running memory value does not reach the preset threshold value, continuously playing the third preset data through the first process.
Wherein the predetermined threshold is less than the maximum memory value.
The method and the device for playing the advertisement data have the advantages that the two processes are set in the application program of the advertisement terminal, after the first process is operated, whether the current operation memory value of the system reaches the preset threshold value or not is detected according to the preset time interval, once the preset threshold value is reached, the advertisement data are continuously played through the second process, the first process is closed to release the memory, and after the memory release is completed, the first process is reused to play the advertisement data. The method and the device have the advantages that the process memory detection logic is added, the memory is timely detected, the memory is released in advance before exceeding the standard, the problems of application program flash back and advertisement blank screen playing for a long time in the advertisement terminal are solved, the process that the first process stops playing advertisement data to release the memory is shielded by starting the second process to play the advertisement, the playing effect is improved, and the product performance is improved.
According to the method and the device, the auxiliary process is started to play the advertisement shielding, the main process automatically quits and releases the memory, then the auxiliary process is started and recovered to play, and the effect that the App does not flash back to the initial interface and the program is played all the time can be achieved.
Moreover, although exemplary embodiments have been described herein, the scope thereof includes any and all embodiments based on the disclosure with equivalent elements, modifications, omissions, combinations (e.g., of various embodiments across), adaptations or alterations. The elements of the claims are to be interpreted broadly based on the language employed in the claims and not limited to examples described in the present specification or during the prosecution of the application, which examples are to be construed as non-exclusive. It is intended, therefore, that the specification and examples be considered as exemplary only, with a true scope and spirit being indicated by the following claims and their full scope of equivalents.
The above description is intended to be illustrative and not restrictive. For example, the above-described examples (or one or more versions thereof) may be used in combination with each other. For example, other embodiments may be used by those of ordinary skill in the art upon reading the above description. In addition, in the foregoing detailed description, various features may be grouped together to streamline the disclosure. This should not be interpreted as an intention that a disclosed feature not claimed is essential to any claim. Rather, the subject matter of the present disclosure may lie in less than all features of a particular disclosed embodiment. Thus, the following claims are hereby incorporated into the detailed description as examples or embodiments, with each claim standing on its own as a separate embodiment, and it is contemplated that these embodiments may be combined with each other in various combinations or permutations. The scope of the disclosure should be determined with reference to the appended claims, along with the full scope of equivalents to which such claims are entitled.
While the present disclosure has been described in detail with reference to the embodiments, the present disclosure is not limited to the specific embodiments, and those skilled in the art can make various modifications and alterations based on the concept of the present disclosure, and the modifications and alterations should fall within the scope of the present disclosure as claimed.