CN109739853A - Array processing method and device, electronic equipment and storage medium - Google Patents

Array processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN109739853A
CN109739853A CN201811579295.7A CN201811579295A CN109739853A CN 109739853 A CN109739853 A CN 109739853A CN 201811579295 A CN201811579295 A CN 201811579295A CN 109739853 A CN109739853 A CN 109739853A
Authority
CN
China
Prior art keywords
data
target
array
sparse array
data cell
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.)
Pending
Application number
CN201811579295.7A
Other languages
Chinese (zh)
Inventor
廖彦文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Internet Security Software Co Ltd
Original Assignee
Beijing Kingsoft Internet Security Software Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Internet Security Software Co Ltd filed Critical Beijing Kingsoft Internet Security Software Co Ltd
Priority to CN201811579295.7A priority Critical patent/CN109739853A/en
Publication of CN109739853A publication Critical patent/CN109739853A/en
Pending legal-status Critical Current

Links

Abstract

The embodiment of the invention provides a data array processing method and device, electronic equipment and a storage medium, which are used for solving the problem that the memory leakage is easily caused because the value of a sparse data array is stored in a strong reference mode. Wherein, the method comprises the following steps: if a target user interface component of a target application is started, adding a target data unit corresponding to the target user interface component into a first sparse array of the target application; if the target user interface component is finished, executing garbage recycling operation; and if the first sparse array comprises the target data unit, performing weak reference processing on the first sparse array to obtain a second sparse array. By implementing the embodiment of the invention, the memory leakage can be avoided.

Description

Array manipulation method, apparatus, electronic equipment and storage medium
Technical field
The present invention relates to computer fields, and in particular to a kind of array manipulation method, apparatus, electronic equipment and storage are situated between Matter.
Background technique
The data type that sparse array (SparseArray) is often used in current Android (Android) exploitation, for depositing Chu Jian -- the case where value is to (key-value), wherein key is stored in an integer int array, and value is stored in one In Object array.And value value is stored in an Object array in a manner of strongly reference, is increased in potential Deposit risk of leakage.
Summary of the invention
The embodiment of the present invention provides a kind of array manipulation method, apparatus, electronic equipment and storage medium, sparse for solving The problem of value of array is stored in a manner of strongly reference, easily causes memory overflow.
First aspect of the embodiment of the present invention provides a kind of array manipulation method, comprising:
If starting the target user interface component of target application, by the corresponding number of targets of the target user interface component It is added in the first sparse array of the target application according to unit;
If terminating the target user interface component, garbage collection operation is executed;
If the first sparse array includes the target data unit, the described first sparse array is subjected to weak reference Processing, obtains the second sparse array.
In conjunction with the embodiment of the present invention in a first aspect, first aspect of the embodiment of the present invention the first possible implementation In, the first sparse array includes multiple first data cells, and it is described that described first sparse array is subjected to weak reference processing, Obtain the second sparse array, comprising:
It is newly-built to refer to sparse array;
The corresponding data of one first data cell every in the multiple first data cell are subjected to weak reference processing, are obtained Multiple second data cells, the array serial number of corresponding first data cell of every one second data cell;
According to the array serial number of one second data cell every in the multiple second data cell, successively by the multiple Two data cells are added to the sparse array of the reference, obtain the described second sparse array.
In conjunction with the possible implementation of the first of first aspect of the embodiment of the present invention or first aspect, implement in the present invention In second of possible implementation of example first aspect, described first sparse array is subjected to weak reference processing described, is obtained To after the second sparse array, the method also includes:
Rewrite the corresponding call method of the described second sparse array.
In conjunction with second of possible implementation of first aspect of the embodiment of the present invention, in first aspect of the embodiment of the present invention The third possible implementation in, it is described to rewrite described the if the call method includes deleting third data cell The corresponding call method of two sparse arrays, comprising:
Obtain the target array serial number of input;
If the target array serial number corresponds to the third data cell, according to target array serial number deletion Third data cell.
In conjunction with second of possible implementation of first aspect of the embodiment of the present invention, in first aspect of the embodiment of the present invention The 4th kind of possible implementation in, if the call method include modify third data cell data, the rewriting The corresponding call method of the second sparse array, comprising:
Obtain the target array serial number and modification data of input;
If the target array serial number corresponds to the third data cell, the modification data are carried out at weak reference Reason, obtains target modification data;
It is the target modification data by the data modification of the third data cell according to the target data serial number.
In conjunction with second of possible implementation of first aspect of the embodiment of the present invention, in first aspect of the embodiment of the present invention The 5th kind of possible implementation in, it is described to rewrite described the if the call method includes searching third data cell The corresponding call method of two sparse arrays, comprising:
Obtain the search criterion of input;
If it is determined that the search criterion corresponds to the third data cell, then the corresponding number of the third data cell is removed According to weak reference, obtain target data;
Export the target data.
In conjunction with second of possible implementation of first aspect of the embodiment of the present invention, in first aspect of the embodiment of the present invention The 6th kind of possible implementation in, it is described if the call method includes the size for calculating the second sparse array Rewrite the corresponding call method of the described second sparse array, comprising:
Obtaining the corresponding data of each data cell in the described second sparse array is not empty element number;
Determine that the element number is the size of the described second sparse array.
Second aspect of the embodiment of the present invention provides a kind of array manipulation device, comprising:
Adding unit, if the target user interface component for starting target application, by the target user interface group The corresponding target data unit of part is added in the first sparse array of the target application;
Unit is cleared up, if executing garbage collection operation for terminating the target user interface component;
Weak reference unit is dilute by described first if including the target data unit for the described first sparse array It dredges array and carries out weak reference processing, obtain the second sparse array.
In conjunction with second aspect of the embodiment of the present invention, in the first possible implementation of second aspect of the embodiment of the present invention In, the first sparse array includes multiple first data cells, and the weak reference unit is specifically used for newly-built with reference to sparse number Group;The corresponding data of one first data cell every in the multiple first data cell are subjected to weak reference processing, are obtained multiple Second data cell, the array serial number of corresponding first data cell of every one second data cell;According to the multiple second The array serial number of every one second data cell, is successively added to the reference for the multiple second data cell in data cell Sparse array obtains the described second sparse array.
In conjunction with the possible implementation of the first of second aspect of the embodiment of the present invention or second aspect, implement in the present invention In second of possible implementation of example second aspect, described device further include:
Rewriting unit, for rewriteeing the corresponding call method of the described second sparse array.
In conjunction with second of possible implementation of second aspect of the embodiment of the present invention, in second aspect of the embodiment of the present invention The third possible implementation in, if the call method includes deleting third data cell, rewriting unit tool Body is used to obtain the target array serial number of input;If the target array serial number corresponds to the third data cell, according to institute It states target array serial number and deletes the third data cell.
In conjunction with second of possible implementation of second aspect of the embodiment of the present invention, in second aspect of the embodiment of the present invention The 4th kind of possible implementation in, if the call method include modify third data cell data, the rewriting Unit is specifically used for obtaining the target array serial number of input and modification data;If the target array serial number corresponds to the third number According to unit, then the modification data is subjected to weak reference processing, obtains target modification data;According to the target data serial number, It is the target modification data by the data modification of the third data cell.
In conjunction with second of possible implementation of second aspect of the embodiment of the present invention, in second aspect of the embodiment of the present invention The 5th kind of possible implementation in, if the call method include search third data cell data, the rewriting Unit is specifically used for obtaining the search criterion of input;If it is determined that the search criterion corresponds to the third data cell, then remove The weak reference of the corresponding data of the third data cell, obtains target data;Export the target data.
In conjunction with second of possible implementation of second aspect of the embodiment of the present invention, in second aspect of the embodiment of the present invention The 6th kind of possible implementation in, it is described if the call method includes the size for calculating the second sparse array Rewriting unit is not empty element number specifically for the corresponding data of data cell each in the acquisition second sparse array; Determine that the element number is the size of the described second sparse array.
The third aspect of the embodiment of the present invention provide a kind of electronic equipment, comprising: shell, processor, memory, circuit board and Power circuit, wherein circuit board is placed in the space interior that shell surrounds, and processor and memory setting are on circuit boards;Electricity Source circuit, for each circuit or the device power supply for electronic equipment;Memory is for storing executable program code;Processor Program corresponding with executable program code is run by reading the executable program code stored in memory, for holding The array manipulation method that row first aspect of the embodiment of the present invention provides.
Fourth aspect of the embodiment of the present invention provides a kind of non-transitorycomputer readable storage medium, wherein the storage Medium realizes that first aspect of the embodiment of the present invention mentions for storing computer program, when the computer program is executed by processor The array manipulation method of confession.
In the embodiment of the present invention, if the target user interface component of starting target application, by the target user interface The corresponding target data unit of component is added in the first sparse array of the target application.If terminating target user circle Face component, then execute garbage collection operation, if the first sparse array includes the target data unit, illustrates the target Data cell is stored in a manner of strongly reference, in this way, the described first sparse array is carried out weak reference processing to obtain To the second sparse array, then the second sparse array includes that data cell is revised as weak reference object, to can avoid memory Leakage.
Detailed description of the invention
It to describe the technical solutions in the embodiments of the present invention more clearly, below will be to needed in the embodiment Attached drawing is briefly described, it should be apparent that, drawings in the following description are some embodiments of the invention, general for this field For logical technical staff, without creative efforts, it is also possible to obtain other drawings based on these drawings.
Fig. 1 is a kind of flow diagram of array manipulation method provided in an embodiment of the present invention;
Fig. 2 is the flow diagram of another array manipulation method provided in an embodiment of the present invention;
Fig. 3 is a kind of structural schematic diagram of array manipulation device provided in an embodiment of the present invention;
Fig. 4 is the structural schematic diagram of another array manipulation device provided in an embodiment of the present invention;
Fig. 5 is the structure chart of a kind of electronic equipment provided in an embodiment of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation description, it is clear that described embodiments are some of the embodiments of the present invention, instead of all the embodiments.Based on this hair Embodiment in bright, every other implementation obtained by those of ordinary skill in the art without making creative efforts Example, shall fall within the protection scope of the present invention.
Term " first ", " second " and " third " in description and claims of this specification and attached drawing etc. are to be used for Different objects are distinguished, are not use to describe a particular order.In addition, term " includes " and " having " and their any deformations, It is intended to cover and non-exclusive includes.Such as it contains the process, method of a series of steps or units, system, product or sets It is standby to be not limited to listed step or unit, but optionally further comprising the step of not listing or unit, or optionally It further include the other step or units intrinsic for these process, methods, product or equipment.
Referenced herein " embodiment " is it is meant that a particular feature, structure, or characteristic described can wrap in conjunction with the embodiments Containing at least one embodiment of the present invention.Each position in the description occur the phrase might not each mean it is identical Embodiment, nor the independent or alternative embodiment with other embodiments mutual exclusion.Those skilled in the art explicitly and Implicitly understand, embodiment described herein can be combined with other embodiments.
Electronic equipment described in the embodiment of the present invention may include smart phone (such as Android phone), tablet computer, Palm PC, laptop, mobile internet device (MID, Mobile Internet Devices) or wearable device It is only citing Deng, electronic equipment, and it is non exhaustive, including but not limited to electronic equipment.
The embodiment of the present invention provides a kind of array manipulation method, apparatus, electronic equipment and storage medium, sparse for solving The problem of value of array is stored in a manner of strongly reference, easily causes memory overflow.
Wherein, SparseArray is a kind of key-value type Method of Data Organization that Android is provided, its key is deposited In an int array, value is stored in an Object array for storage.
Strongly reference refers to that an object is somewhere used in program, which would not be automatic by system Recycling, code are as follows:
Object obj=new Object ();// corresponding object, such as obj.equels directly can be obtained by obj (new Object());
And a strongly reference of the obj object to new Object below in this way, only as obj, this reference is released it Afterwards, object can be just released, and therefore, the object of strongly reference is likely to cause memory overflow.
Weak reference corresponding with strongly reference refers to that an object is somewhere used in program, and system is when needed The memory of the object can be recycled.Its code are as follows:
Object obj=new Object ();
WeakReference<Object>wf=new WeakReference<Object>(obj);
During the region of memory that it is administered in Garbage Collector thread scans, once having found only has weak reference Object can all recycle its memory whether current memory space is enough or not.Therefore, the object of weak reference is difficult to cause interior Deposit leakage.
Referring to Fig. 1, Fig. 1 is a kind of flow chart of array manipulation method provided in an embodiment of the present invention.As shown in Figure 1, This method may comprise steps of.
If step S101, starting the target user interface component of target application, by the target user interface component pair The target data unit answered is added in the first sparse array of the target application.
User interface components (Activity) are the user interface components of android system, are mainly used for showing interactive boundary Face.In Android, Activity is managed by way of a kind of Activity stack, the example of an Activity State determines its position in stack.Activity in foreground always on the top of stack, when foreground Activity because When abnormal or other reasons are destroyed, the Activity in the stack second layer will be activated, and float to stack top.When new When Activity starts stacking, former Activity can be pressed into the second layer of stack.Position of one Activity in stack becomes Change the conversion for reflecting it between different conditions.
In Android, Activity possesses active state or operating status (active or running), pause State (Paused), halted state (Stopped) and destruction state (Killed).Wherein: when a new Activity start into After stack, it is shown in screen front end, and processing is the top (Activity stack top) in stack, is now in visible and can be with The state of activation of user's interaction, is called active state or operating status;It is new non-complete by one when Activity loses focus Activity or transparent Activity of screen is placed on stack top, and state at this time is called halted state;When one Activity is completely covered by other Activity, is called halted state;When an Activity be halted state or Halted state, system can delete the Activity from memory, be called destruction state.
In this application, target application can be any application in electronic equipment;Target user interface component is the mesh Mark applies corresponding any Activity, is also possible to the Activity compiled dedicated for test, it is not limited here.
If being appreciated that starting target Activity, target Activity is in active state or operating status, If target end Activity, placed in a suspend state or halted state, i.e. electronic equipment can be by the mesh by target Activity Mark Activity is deleted from memory.
In this application, the first sparse array is any sparse array stored in target application, and target data unit is Electronic equipment is the sparse unit that target Activity is established, i.e. the target data unit also includes corresponding Key and value.
If step S102, terminating the target user interface component, garbage collection operation is executed.
Wherein, garbage reclamation (Garbage Collection, GC) operation is executed for clearing up the weak reference pair in memory As, it will be understood that if the first sparse array includes target data unit, illustrate that the data cell in the first sparse array is It is stored in a manner of strongly reference, otherwise, can illustrate that the data cell in the first sparse array is the side with weak reference What formula was stored.
If step S103, the described first sparse array includes the target data unit, by the described first sparse array Weak reference processing is carried out, the second sparse array is obtained.
How the application is for carry out weak reference processing without limitation, as an alternative embodiment, described first Sparse array includes multiple first data cells, described that described first sparse array is carried out weak reference processing, and it is dilute to obtain second Dredge array, comprising: newly-built to refer to sparse array;By the corresponding number of one first data cell every in the multiple first data cell According to weak reference processing is carried out, multiple second data cells are obtained;According to one second data every in the multiple second data cell The multiple second data cell is successively added to the sparse array of the reference, obtains described second by the array serial number of unit Sparse array.
Wherein, with reference to sparse array for temporarily storing the second data cell, corresponding one of every one second data cell the The array serial number of one data cell, then the second sparse array will only be corresponded in the first sparse array the array location of array serial number into The processing of row weak reference.
As an example it is assumed that multiple first data cells are data cell A, data cell B and data cell C, wherein counting According to the array serial number 0 of unit A, the array serial number 1 of data cell B, the array serial number 2 of data cell C, then first by data Unit A carries out weak reference and handles to obtain data cell D, data cell B and carry out weak reference to handle to obtain data cell E, data sheet First C carries out weak reference and handles to obtain data cell F, i.e., multiple second data cells are data cell D, data cell E and data Unit F, and therefore data cell D, data cell E and the corresponding array serial number 0,1,2 of data unit F will successively count It is added to reference to sparse array according to cells D, data cell E and data unit F to obtain the second sparse array.
It is appreciated that the corresponding data of the first data cell are carried out weak reference processing to obtain the second data sheet respectively Member is successively added to reference to sparse data then according to the corresponding data sequence number of each second data cell, and is completed in addition When, the second sparse array is obtained, so that corresponding second data cell is weak reference object in the second sparse array, to avoid interior Deposit leakage.
In addition, above-mentioned weak reference method is unrelated with the system version of Android, therefore, the flexible of array manipulation method can be improved Property.
It, will be described if the target user interface component of starting target application in the array manipulation method described in Fig. 1 The corresponding target data unit of target user interface component is added in the first sparse array of the target application.If terminating institute Target user interface component is stated, then executes garbage collection operation, if the first sparse array includes the target data unit, Then illustrate that the target data unit is stored in a manner of strongly reference, in this way, the described first sparse array is carried out weak Reference processing is to obtain the second sparse array, then the second sparse array includes that data cell is revised as weak reference object, from And it can avoid RAM leakage.
Referring to Fig. 2, Fig. 2 is the flow chart of another array manipulation method provided in an embodiment of the present invention.Such as Fig. 2 institute Show, this method may comprise steps of.
If step S201, starting the target user interface component of target application, by the target user interface component pair The target data unit answered is added in the first sparse array of the target application.
If step S202, terminating the target user interface component, garbage collection operation is executed.
If step S203, the described first sparse array includes the target data unit, by the described first sparse array Weak reference processing is carried out, the second sparse array is obtained.
Wherein, step S201-S203 can refer to 1 shown in step S101-S103 in array manipulation method, it is no longer superfluous herein It states.
Step S204, the corresponding call method of the sparse array of rewriting described second.
In this application, the corresponding call method of the second sparse array may include calculating size size, increasing key-value pair (append, put), modification key-value pair (put, setValueAt), delete key-value pair (delete, remove, removeAt or Clear, wherein delete, remove, removeAt are used for delete key, and clear is for deleting whole), search (indexOfKey, indexOfValue, keyAt, valueAt etc., wherein indexOfKey is for checking key position; For indexOfValue for checking value position, it's not true returns to -1;KeyAt is used to check the key of which position; ValueAt is used to check the value of which position), (Cloneable) interface can be cloned etc., it is not limited here.
In a possible embodiment, if the call method includes deleting third data cell, the rewriting institute State the corresponding call method of the second sparse array, comprising: obtain the target array serial number of input;If the target array serial number pair The third data cell is answered, then the third data cell is deleted according to the target array serial number.
Wherein, delete third data cell data call method can by delete, remove above-mentioned, RemoveAt is realized.If being appreciated that, the target data serial number obtained corresponds to the third data cell, deletes the number of targets The corresponding third data cell of group serial number, then no matter third data cell is deleted in a manner of strongly reference or weak reference mode Later, it not will cause RAM leakage.
In a possible embodiment, described if the call method includes the data for modifying third data cell Rewrite the corresponding call method of the described second sparse array, comprising: obtain the target array serial number and modification data of input;If institute It states target array serial number and corresponds to the third data cell, then the modification data are subjected to weak reference processing, obtain target and repair Change data;It is the target modification data by the data modification of the third data cell according to the target data serial number.
Wherein, the call method of the data of modification third data cell can be realized by put, setValueAt above-mentioned, It should be noted that if key is not present, put is changing to add new key-value pair.
If being appreciated that, the target data serial number obtained corresponds to the third data cell, and it is weak will to modify data progress The data modification of the third data cell is institute according to the target array serial number to obtain target modification data by reference processing State target modification data, that is to say, that the data of the third data cell after modifying are stored in a manner of weak reference, thus It not will cause RAM leakage.
In a possible embodiment, described if the call method includes the data for searching third data cell Rewrite the corresponding call method of the described second sparse array, comprising: obtain the search criterion of input;If it is determined that the search criterion Corresponding third data cell, then remove the weak reference of the corresponding data of the third data cell, obtain target data;Output institute State target data.
Wherein, the call method for searching the data of third data cell can be realized by valueAt above-mentioned.It can manage Solution, if obtain search criterion correspond to third data cell, remove the weak reference of the corresponding data of third data cell with Target data is obtained, target data is then exported, in this way, the corresponding data of third data cell are removed weak reference, i.e., Return to numerical value itself.
In a possible embodiment, if the call method includes the size for calculating the second sparse array, The corresponding call method of the sparse array of the rewriting described second, comprising: obtain each data sheet in the second sparse array The corresponding data of member are not empty element number;Determine that the element number is the size of the described second sparse array.
Wherein, the call method for calculating the size of the second sparse array can be realized by size above-mentioned.If being appreciated that Data in second sparse array are sky, then it represents that the data are no longer cited, so that obtaining data not is empty unit number Amount, and using the element number as the size in the second sparse array, in this way, convenient for improving the accuracy for calculating size.
In a possible embodiment, if the call method includes the 5th data cell of addition, the rewriting institute State the corresponding call method of the second sparse array, comprising:
Obtain the addition data of input;
The addition data are subjected to weak reference processing, obtain target addition data;
In the end of the described second sparse array, addition adds data with the target, obtains the 5th data cell.
It is appreciated that addition data are first carried out weak reference processing to obtain target addition data, then target is added into number According to addition in the end of the second sparse array, the 5th data cell is added with this.
It, will be described if the target user interface component of starting target application in the array manipulation method described in Fig. 2 The corresponding target data unit of target user interface component is added in the first sparse array of the target application.If terminating institute Target user interface component is stated, then executes garbage collection operation, if the first sparse array includes the target data unit, Then illustrate that the target data unit is stored in a manner of strongly reference, in this way, the described first sparse array is carried out weak Reference processing is to obtain the second sparse array, then the second sparse array includes that data cell is revised as weak reference object, from And it can avoid RAM leakage.Finally, being written over to the call method of the second sparse array, it can be improved and call the second sparse array Method accuracy.
Referring to Fig. 3, Fig. 3 is a kind of structure chart of array manipulation device provided in an embodiment of the present invention.As shown in figure 3, The device 300 may include:
Adding unit 301, if the target user interface component for starting target application, by the target user interface The corresponding target data unit of component is added in the first sparse array of the target application;
Unit 302 is cleared up, if executing garbage collection operation for terminating the target user interface component;
Weak reference unit 303, if including the target data unit for the described first sparse array, by described first Sparse array carries out weak reference processing, obtains the second sparse array.
It will be appreciated that the function of each functional unit of the array manipulation device 300 of the present embodiment can be according to the above-mentioned side Fig. 1 The method of method embodiment implements, and details are not described herein again.
As a kind of alternative embodiment, the first sparse array includes multiple first data cells, it is described will be described First sparse array carries out weak reference processing, and in terms of obtaining the second sparse array, the weak reference unit 303 is specifically used for newly-built With reference to sparse array;The corresponding data of one first data cell every in the multiple first data cell are carried out at weak reference Reason obtains multiple second data cells, the array serial number of corresponding first data cell of every one second data cell;According to institute The array serial number of every one second data cell in multiple second data cells is stated, successively adds the multiple second data cell Sparse array is referred to described, obtains the described second sparse array.
It, will be described if the target user interface component of starting target application in the array manipulation device described in Fig. 3 The corresponding target data unit of target user interface component is added in the first sparse array of the target application.If terminating institute Target user interface component is stated, then executes garbage collection operation, if the first sparse array includes the target data unit, Then illustrate that the target data unit is stored in a manner of strongly reference, in this way, the described first sparse array is carried out weak Reference processing is to obtain the second sparse array, then the second sparse array includes that data cell is revised as weak reference object, from And it can avoid RAM leakage.
Referring to Fig. 4, Fig. 4 is the structure chart of another array manipulation device provided in an embodiment of the present invention.Such as Fig. 4 institute Show, which may include:
Adding unit 401, if the target user interface component for starting target application, by the target user interface The corresponding target data unit of component is added in the first sparse array of the target application;
Unit 402 is cleared up, if executing garbage collection operation for terminating the target user interface component;
Weak reference unit 403, if including the target data unit for the described first sparse array, by described first Sparse array carries out weak reference processing, obtains the second sparse array;
Rewriting unit 404, for rewriteeing the corresponding call method of the described second sparse array.
As a kind of alternative embodiment, the first sparse array includes multiple first data cells, the weak reference list Member 403 is specifically used for newly-built with reference to sparse array;One first data cell every in the multiple first data cell is corresponding Data carry out weak reference processing, obtain multiple second data cells, corresponding first data cell of every one second data cell Array serial number;It, successively will be described more according to the array serial number of one second data cell every in the multiple second data cell A second data cell is added to the sparse array of the reference, obtains the described second sparse array.
As a kind of alternative embodiment, if the call method includes deleting third data cell, the rewriting unit 404 are specifically used for obtaining the target array serial number of input;If the target array serial number corresponds to the third data cell, root The third data cell is deleted according to the target array serial number.
It is described heavy if the call method includes the data for modifying third data cell as a kind of alternative embodiment R/w cell 404 is specifically used for obtaining the target array serial number of input and modification data;If described in the target array serial number is corresponding The modification data are then carried out weak reference processing, obtain target modification data by third data cell;According to the target data The data modification of the third data cell is the target modification data by serial number.
It is described heavy if the call method includes the data for searching third data cell as a kind of alternative embodiment R/w cell 404 is specifically used for obtaining the search criterion of input;If it is determined that the search criterion corresponds to the third data cell, then The weak reference for removing the corresponding data of the third data cell, obtains target data;Export the target data.
As a kind of alternative embodiment, if the call method includes the size for calculating the second sparse array, institute It is not empty unit that rewriting unit 404, which is stated, specifically for the corresponding data of data cell each in the acquisition second sparse array Quantity;Determine that the element number is the size of the described second sparse array.
It will be appreciated that the function of each functional unit of the array manipulation device 400 of the present embodiment can according to above-mentioned Fig. 1 and The method of Fig. 2 embodiment of the method implements, and details are not described herein again.
It, will be described if the target user interface component of starting target application in the array manipulation device described in Fig. 4 The corresponding target data unit of target user interface component is added in the first sparse array of the target application.If terminating institute Target user interface component is stated, then executes garbage collection operation, if the first sparse array includes the target data unit, Then illustrate that the target data unit is stored in a manner of strongly reference, in this way, the described first sparse array is carried out weak Reference processing is to obtain the second sparse array, then the second sparse array includes that data cell is revised as weak reference object, from And it can avoid RAM leakage.Finally, being written over to the call method of the second sparse array, it can be improved and call the second sparse array Method accuracy.
Referring to Fig. 5, Fig. 5 is electronic equipment provided in an embodiment of the present invention.Wherein, which is suitable for hand The electronic equipments such as machine, tablet computer.As shown in figure 5, the electronic equipment may include shell 510, processor 520, memory 530, circuit board 540 and power circuit 550, wherein circuit board 540 is placed in the space interior that shell surrounds, 520 He of processor Memory 530 is arranged on circuit board 540;Power circuit 550, for each circuit or the device power supply for electronic equipment;It deposits Reservoir 530 is for storing executable program code;Processor 520 is by reading the executable program generation stored in memory 530 Code runs program corresponding with executable program code, for executing following steps:
If starting the target user interface component of target application, by the corresponding number of targets of the target user interface component It is added in the first sparse array of the target application according to unit;
If terminating the target user interface component, garbage collection operation is executed;
If the first sparse array includes the target data unit, the described first sparse array is subjected to weak reference Processing, obtains the second sparse array.
As a kind of alternative embodiment, the first sparse array includes multiple first data cells, it is described will be described First sparse array carries out weak reference processing, and in terms of obtaining the second sparse array, above-mentioned processor 520 is specifically used for executing following Operation:
It is newly-built to refer to sparse array;
The corresponding data of one first data cell every in the multiple first data cell are subjected to weak reference processing, are obtained Multiple second data cells, the array serial number of corresponding first data cell of every one second data cell;
According to the array serial number of one second data cell every in the multiple second data cell, successively by the multiple Two data cells are added to the sparse array of the reference, obtain the described second sparse array.
As a kind of alternative embodiment, described first sparse array is subjected to weak reference processing described, it is dilute to obtain second After dredging array, above-mentioned processor 520 is also used to execute following operation:
Rewrite the corresponding call method of the described second sparse array.
As a kind of alternative embodiment, if the call method includes deleting third data cell, in the rewriting institute In terms of stating the corresponding call method of the second sparse array, above-mentioned processor 520 is specifically used for executing following operation:
Obtain the target array serial number of input;
If the target array serial number corresponds to the third data cell, according to target array serial number deletion Third data cell.
As a kind of alternative embodiment, if the call method includes the data for modifying third data cell, described In terms of rewriteeing the corresponding call method of the described second sparse array, above-mentioned processor 520 is specifically used for executing following operation:
Obtain the target array serial number and modification data of input;
If the target array serial number corresponds to the third data cell, the modification data are carried out at weak reference Reason, obtains target modification data;
It is the target modification data by the data modification of the third data cell according to the target data serial number.
As a kind of alternative embodiment, if the call method includes the data for searching third data cell, described In terms of rewriteeing the corresponding call method of the described second sparse array, above-mentioned processor 520 is specifically used for executing following operation:
Obtain the search criterion of input;
If it is determined that the search criterion corresponds to the third data cell, then the corresponding number of the third data cell is removed According to weak reference, obtain target data;
Export the target data.
As a kind of alternative embodiment, if the call method includes the size for calculating the second sparse array, In terms of the corresponding call method of the sparse array of the rewriting described second, above-mentioned processor 520 is specifically used for executing following operate:
Obtaining the corresponding data of each data cell in the described second sparse array is not empty element number;
Determine that the element number is the size of the described second sparse array.
In the electronic equipment described in Fig. 5, if the target user interface component of starting target application, by the target The corresponding target data unit of user interface components is added in the first sparse array of the target application.If terminating the mesh User interface components are marked, then executes garbage collection operation, if the first sparse array includes the target data unit, says The bright target data unit is stored in a manner of strongly reference, in this way, the described first sparse array is carried out weak reference Processing is to obtain the second sparse array, then the second sparse array includes that data cell is revised as weak reference object, so as to Avoid RAM leakage.
A kind of non-transitorycomputer readable storage medium is provided in one embodiment, is stored thereon with computer journey Sequence, wherein the array manipulation method of embodiment one or embodiment two is realized when the computer program is executed by processor.
In several embodiments provided herein, it should be understood that disclosed system, device and method can be with It realizes by another way.For example, the apparatus embodiments described above are merely exemplary, for example, module or unit Division, only a kind of logical function partition, there may be another division manner in actual implementation, such as multiple units or group Part can be combined or can be integrated into another system, or some features can be ignored or not executed.Another point, it is shown Or the mutual coupling, direct-coupling or communication connection discussed can be through some interfaces, device or unit it is indirect Coupling or communication connection can be electrical property, mechanical or other forms.
Unit may or may not be physically separated as illustrated by the separation member, shown as a unit Component may or may not be physical unit, it can and it is in one place, or may be distributed over multiple networks On unit.It can some or all of the units may be selected to achieve the purpose of the solution of this embodiment according to the actual needs.
It, can also be in addition, each functional unit in each embodiment of the application can integrate in one processing unit It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Integrated unit was both It can take the form of hardware realization, can also realize in the form of software functional units.
It, can if integrated unit is realized in the form of SFU software functional unit and when sold or used as an independent product To be stored in a computer readable storage medium.Based on this understanding, the technical solution of the application substantially or Say that all or part of the part that contributes to existing technology or the technical solution can embody in the form of software products Out, which is stored in a storage medium, including some instructions are used so that a computer equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute each implementation of the application The all or part of the steps of example method.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic or disk etc. is various to deposit Store up the medium of program code.
More than, the only specific embodiment of the application, but the protection scope of the application is not limited thereto, and it is any to be familiar with Those skilled in the art within the technical scope of the present application, can easily think of the change or the replacement, and should all cover Within the protection scope of the application.Therefore, the protection scope of the application should be subject to the protection scope in claims.

Claims (10)

1. a kind of array manipulation method characterized by comprising
If starting the target user interface component of target application, by the corresponding target data list of the target user interface component Member is added in the first sparse array of the target application;
If terminating the target user interface component, garbage collection operation is executed;
If the first sparse array includes the target data unit, the described first sparse array is carried out at weak reference Reason, obtains the second sparse array.
2. the method according to claim 1, wherein the first sparse array includes multiple first data sheets Member, it is described that described first sparse array is subjected to weak reference processing, obtain the second sparse array, comprising:
It is newly-built to refer to sparse array;
The corresponding data of one first data cell every in the multiple first data cell are subjected to weak reference processing, are obtained multiple Second data cell, the array serial number of corresponding first data cell of every one second data cell;
According to the array serial number of one second data cell every in the multiple second data cell, successively by the multiple second number It is added to the sparse array of the reference according to unit, obtains the described second sparse array.
3. method according to claim 1 or 2, which is characterized in that described first sparse array is carried out weak draw described With processing, after obtaining the second sparse array, the method also includes:
Rewrite the corresponding call method of the described second sparse array.
4. according to the method described in claim 3, it is characterized in that, if the call method include delete third data cell, The then corresponding call method of the sparse array of the rewriting described second, comprising:
Obtain the target array serial number of input;
If the target array serial number corresponds to the third data cell, the third is deleted according to the target array serial number Data cell.
5. according to the method described in claim 3, it is characterized in that, if the call method includes modification third data cell Data, then it is described to rewrite the corresponding call method of the second sparse array, comprising:
Obtain the target array serial number and modification data of input;
If the target array serial number corresponds to the third data cell, the modification data are subjected to weak reference processing, are obtained To target modification data;
It is the target modification data by the data modification of the third data cell according to the target data serial number.
6. according to the method described in claim 3, it is characterized in that, if the call method includes searching third data cell Data, then it is described to rewrite the corresponding call method of the second sparse array, comprising:
Obtain the search criterion of input;
If it is determined that the search criterion corresponds to the third data cell, then the corresponding data of the third data cell are removed Weak reference obtains target data;
Export the target data.
7. device according to claim 3, which is characterized in that if the call method includes calculating the second sparse number The size of group, then it is described to rewrite the corresponding call method of the second sparse array, comprising:
Obtaining the corresponding data of each data cell in the described second sparse array is not empty element number;
Determine that the element number is the size of the described second sparse array.
8. a kind of array manipulation device characterized by comprising
Adding unit, if the target user interface component for starting target application, by the target user interface component pair The target data unit answered is added in the first sparse array of the target application;
Unit is cleared up, if executing garbage collection operation for terminating the target user interface component;
Weak reference unit, if including the target data unit for the described first sparse array, by the described first sparse number Group carries out weak reference processing, obtains the second sparse array.
9. a kind of electronic equipment, comprising: shell, processor, memory, circuit board and power circuit, wherein circuit board is placed in The space interior that shell surrounds, processor and memory setting are on circuit boards;Power circuit, for for each of electronic equipment Circuit or device power supply;Memory is for storing executable program code;Processor is held by what is stored in reading memory Line program code runs program corresponding with executable program code, for executing as described in the claim any one of 1-7 Method.
10. a kind of non-transitorycomputer readable storage medium, is stored thereon with computer program, which is characterized in that the meter The method as described in any in claim 1-7 is realized when calculation machine program is executed by processor.
CN201811579295.7A 2018-12-21 2018-12-21 Array processing method and device, electronic equipment and storage medium Pending CN109739853A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811579295.7A CN109739853A (en) 2018-12-21 2018-12-21 Array processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811579295.7A CN109739853A (en) 2018-12-21 2018-12-21 Array processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN109739853A true CN109739853A (en) 2019-05-10

Family

ID=66359612

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811579295.7A Pending CN109739853A (en) 2018-12-21 2018-12-21 Array processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN109739853A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140223084A1 (en) * 2013-02-06 2014-08-07 Samsung Electronics Co., Ltd. Memory system and related method of operation
CN104750137A (en) * 2015-03-17 2015-07-01 航天东方红卫星有限公司 Search table based satellite temperature control data processing method
CN107015866A (en) * 2017-03-23 2017-08-04 腾讯科技(深圳)有限公司 A kind of data processing method and device
CN107357650A (en) * 2017-06-06 2017-11-17 武汉斗鱼网络科技有限公司 A kind of automatic method for releasing of internal memory based on picture resource and system
CN107544846A (en) * 2017-08-08 2018-01-05 武汉斗鱼网络科技有限公司 A kind of EMS memory management process, device and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140223084A1 (en) * 2013-02-06 2014-08-07 Samsung Electronics Co., Ltd. Memory system and related method of operation
CN104750137A (en) * 2015-03-17 2015-07-01 航天东方红卫星有限公司 Search table based satellite temperature control data processing method
CN107015866A (en) * 2017-03-23 2017-08-04 腾讯科技(深圳)有限公司 A kind of data processing method and device
CN107357650A (en) * 2017-06-06 2017-11-17 武汉斗鱼网络科技有限公司 A kind of automatic method for releasing of internal memory based on picture resource and system
CN107544846A (en) * 2017-08-08 2018-01-05 武汉斗鱼网络科技有限公司 A kind of EMS memory management process, device and electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
VVENGZT: "Android优化中弱引用WeakReference的知识", 《HTTP://BLOG.CSDN.NET/PRINTFCC/ARTICLE/DETAILS/79131479》 *

Similar Documents

Publication Publication Date Title
CN103984641B (en) A kind of memory space recovery method and its device based on simplify configuration technology
CN104424015B (en) A kind of virtual machine management method and device
CN103577329B (en) Snapshot management method and device
CN105760199B (en) A kind of application resource loading method and its equipment
CN103339616A (en) Incremental class unloading in a region-based garbage collector
CN101261593B (en) Method and system for enabling state save and debugging
CN105224332B (en) A kind of application program generation method and device
CN103677674B (en) A kind of data processing method and device
CN103164490A (en) Method and device for achieving high-efficient storage of data with non-fixed lengths
CN103019691A (en) Transformation method for extract, transform and load (ETL) operation relation graph and implementation system thereof
CN107870775A (en) A kind of update method of processor and BootLoader program
CN102946413A (en) Method and system for resource preprocessing in dispatching and deployment performing process of virtual machine
CN103412825A (en) Internal storage releasing method and device
CN110096521A (en) Log information processing method and device
CN104933051A (en) File storage space recovery method and device
CN104850505A (en) Memory management method and system based on chain type stacking
CN106293497A (en) The recovery method of junk data and device in watt record filesystem-aware
CN103425729A (en) Managing memory in a computer system
CN101086717B (en) System and method for storing transient state information
US8024374B2 (en) Computer object conversion using an intermediate object
CN105095354A (en) Data updating method and data updating device
CN109739853A (en) Array processing method and device, electronic equipment and storage medium
CN110007860A (en) Method, solid state hard disk and the storage device of garbage disposal based on LSM database
CN108845825A (en) A kind of storage system configuration method, apparatus, equipment and readable storage medium storing program for executing
CN104246716B (en) The processing method and equipment of memory space object

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20190510

RJ01 Rejection of invention patent application after publication