Android-based Handler memory leakage prevention device and method

A memory leak and message technology, applied in the field of Android system security, can solve problems such as application crashes and system freezes, and achieve the effect of improving efficiency and eliminating memory leaks

Inactive Publication Date: 2017-04-26
WUHAN DOUYU NETWORK TECH CO LTD
View PDF6 Cites 19 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

Since this piece of memory has been occupied and cannot be released in time, in other cases, when it is necessary to apply for memory again but cannot apply for enough memory space, the system will freeze, and in severe cases, the application may crash and other consequences.
It can be seen that the memory leak has brought us very bad results.

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Android-based Handler memory leakage prevention device and method
  • Android-based Handler memory leakage prevention device and method

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0050] This embodiment provides an Android-based Handler memory leak prevention device, which includes: an asynchronous Runnable request receiving module, configured to receive a Runnable request of an asynchronous task. The synchronization module is used to store all received Runnable requests of asynchronous tasks synchronously by using the weak reference method. The asynchronous request execution module is used to execute the Runnable request of the asynchronous task, and judges whether there is a message to be sent; the sub-thread execution end module is used to end the sub-thread when there is no message to send. The message sending module is used for sending a message and the weak reference relationship between the message and the asynchronous thread when there is a message to be sent. The message distribution module is used to store the message and the weak reference relationship between the message and the asynchronous thread, and send the message to the main thread fo...

Embodiment 2

[0067] In this embodiment, on the basis of the first embodiment, the device: a doubly linked list is set in the synchronization module to store the Runnable request of the asynchronous task. Method: Store the Runnable request of the asynchronous task in the form of a doubly linked list.

[0068] Each data node of the doubly linked list contains a reference relationship prior to the previous node and a reference relationship next to the next node. Only the first node and the last node will have something special. The prior of the first node is empty because the first node has no previous node. The next of the last node is empty, because the last node has no following node data. All other nodes are saved with prior and next information. The main reason for using a doubly linked list to store all asynchronous tasks is the unique feature of the doubly linked list, which can quickly delete and add data. It is also because of this feature that we chose a doubly linked list fo...

Embodiment 3

[0070] In this embodiment, on the basis of Embodiment 1 or 2, the device: the priority of the thread is also stored in the synchronization module, which is used to remove the Runnable request of the asynchronous task according to the priority. Method: After storing the Runnable request of the asynchronous task, remove the Runnable request of the asynchronous task according to the priority. Such high-priority tasks can be prioritized. After grading, it can guarantee the priority scheduling of urgent tasks.

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention provides an Android-based Handler memory leakage prevention device comprising: an asynchronous Runnable request receiving module used for receiving Runnable requests of asynchronous tasks; a synchronizing module used for synchronizing all received Runnable requests of the asynchronous tasks by adopting a weak quotation method; an asynchronous request execution module used for executing the Runnable requests of the asynchronous tasks and judging whether a message needs to be sent; a sub-line thread execution termination module used for terminating a sub-line thread if there is no message to be sent; a message sending module used for sending a message and a weak quotation relationship between the message and an asynchronous thread when the message needs to be sent; and a message distribution module used for storing the message and the weak quotation relationship between the message and the asynchronous thread and sending the same to a main thread for processing according to the time sequence of the message. According to the Android-based Handler memory leakage prevention device provided by the invention, the weak quotation relationship is introduced to ensure that resources can be smoothly recycled by a garbage collector, and no memory leakage is generated in the case of normal communication of the sub-thread and the main thread.

Description

technical field [0001] The invention belongs to the field of Android system security, and in particular relates to an Android-based Handler memory leak prevention device and method. Background technique [0002] In Android software development, multi-threading technology is more or less used. When using multi-threading technology, there is a problem point, that is, how the sub-thread and the main thread communicate. Android provides us with a relatively easy-to-use tool Handler, which sends messages to the main thread in the sub-thread through the Handler tool. After the main thread receives the message from the sub-thread, it will perform different operations according to different types of messages. [0003] That is to say, the Handler mainly uses the message mechanism to enable the main thread and the sub-thread to communicate. The message mechanism of Handler does solve the problem of communication between the child thread and the main thread, but it also has a potentia...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
IPC IPC(8): G06F9/50G06F9/54
CPCG06F9/5016G06F9/546
Inventor 张磊
Owner WUHAN DOUYU NETWORK TECH CO LTD
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products