CN104714897A - Cache-based list processing method on android platform - Google Patents

Cache-based list processing method on android platform Download PDF

Info

Publication number
CN104714897A
CN104714897A CN201310684441.3A CN201310684441A CN104714897A CN 104714897 A CN104714897 A CN 104714897A CN 201310684441 A CN201310684441 A CN 201310684441A CN 104714897 A CN104714897 A CN 104714897A
Authority
CN
China
Prior art keywords
softreference
cache
bitmap
buffer memory
string
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
CN201310684441.3A
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.)
Aisino Corp
Original Assignee
Aisino Corp
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 Aisino Corp filed Critical Aisino Corp
Priority to CN201310684441.3A priority Critical patent/CN104714897A/en
Publication of CN104714897A publication Critical patent/CN104714897A/en
Pending legal-status Critical Current

Links

Abstract

The invention discloses a cache-based list processing method on an android platform. The cache-based list processing method on the android platform comprises the following steps that S100, two levels of cache are set, wherein the first level of cache is LinkedHashMap<String, Bitmap>, and the second level of cache is ConcurrentHashMap<String, SoftReference<Bitmap>>; S200, the first level of cache reserves the strong reference of Bitmap through the LinkedHashMap<String, Bitmap>, and the size of cache is controlled to be MAX_CAPACITY=10; S300, when data continue to be stored in the cache, the least and recently used elements in the first level of cache are put into the second level of cache ConcurrentHashMap<String, SoftReference<Bitmap>>, and SoftReference of Bitmap is reserved in the second level of cache. The user experience is improved, and resources are saved.

Description

Based on the list disposal route of buffer memory under a kind of Android platform
Technical field
The present invention relates to technical field of the computer network, particularly relate to the list disposal route based on buffer memory under a kind of Android platform.
Background technology
Under Android platform, cpu resource, memory source and Internet resources are all resources at full stretch.List is the conventional control that android is used for showing collective data, and when there being the data needing to read from network or database in gathering, the display of list will be very consuming time.
Summary of the invention
The object of the present invention is to provide the list disposal route based on buffer memory under a kind of Android platform, it improves Consumer's Experience, saves resource.
For realizing the list disposal route based on buffer memory under a kind of Android platform that the object of the invention provides, comprise the steps:
Step S100, arranges two-level cache: first order buffer memory LinkedHashMap<String, Bitmap>; L2 cache ConcurrentHashMap<String, SoftReference<Bitmap>GreatT.G reaT.GT;
Step S200, first order buffer memory LinkedHashMap<String, Bitmap> retain the strongly reference of Bitmap, control the size MAX_CAPACITY=10 of buffer memory;
Step S300, when continuation is in this buffer memory when deposit data, least-recently-used element in level cache is put into L2 cache ConcurrentHashMap<String, SoftReference<Bitmap>GreatT.G reaT.GT, the soft of the Bitmap retained in L2 cache quotes SoftReference.
More preferably, described step S300 also comprises the steps:
Step S310, when establishment SoftReference object, employs a ReferenceQueue object is supplied to SoftReference building method as parameter:
ReferenceQueue queue=new ReferenceQueue();
SoftReference ref=new SoftReference(aMyObject,queue);
Step S320, when described SoftReference while the soft aMyOhject quoted reclaimed by garbage collector, the SoftReference object of ref institute strongly reference is put into ReferenceQueue.
Based on the list disposal route of buffer memory under Android platform of the present invention, it is by arranging two-level cache, effectively raises the efficiency of list in big data quantity situation, improves Consumer's Experience, saves resource.
Accompanying drawing explanation
Fig. 1 is the list process flow figure based on buffer memory under the Android platform according to the present invention's specific embodiment.
Embodiment
In order to make object of the present invention, technical scheme and advantage clearly thorough, below in conjunction with drawings and Examples, the list disposal route based on buffer memory under Android platform of the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
Based on the list disposal route of buffer memory under Android platform of the present invention, as shown in Figure 1, comprise the steps:
Step S100, arranges two-level cache: first order buffer memory LinkedHashMap<String, Bitmap>; L2 cache ConcurrentHashMap<String, SoftReference<Bitmap>GreatT.G reaT.GT;
Step S200, first order buffer memory LinkedHashMap<String, Bitmap> retain the strongly reference of Bitmap, control the size MAX_CAPACITY=10 of buffer memory;
Step S300, when continuation is in this buffer memory when deposit data, least-recently-used element in level cache is put into L2 cache ConcurrentHashMap<String, SoftReference<Bitmap>GreatT.G reaT.GT, the soft of the Bitmap retained in L2 cache quotes SoftReference.
The soft object instance quoted SoftReference and preserve, unless JVM is by OutOfMemory, otherwise can not be reclaimed by GC.This characteristic makes it be particularly suitable for design object Cache.The object that Cache is buffered preferably memory-resident all the time, if but JVM internal memory is critical, causing system crash to there is not OutOfMemoryError, also allowing JVM to reclaim the internal memory of Cache time necessary, treating follow-up suitable opportunity again in data again Load to Cache.Can must have more elasticity by system like this.
Internal memory optimization is in the data access got being gathered to Map, if again quote these data, and just direct acquisition from Map set, a problem can be caused like this, if the data in Map set are many especially, such as access 1,000,000 data, internal memory so likely will be caused to overflow.This is because Map set is the set of strongly reference, as why not Map set being set to sky, this set Java Virtual Machine would not recycle it, internal memory will be caused to overflow when the size of data in Map has exceeded memory size.Softly quote softreference in order to avoid this exception will use, soft quote with the difference of strongly reference as follows:
Hardreference gives tacit consent to the type that new object is out all this strong application, as long as quoting of also retaining of object, he would not by garbage reclamation.
Softreference he be the packaging type that java virtual machine provides to us, java virtual machine can be tried one's best and be retained this object for a long time, and when java virutal machine memory deficiency time, java virtual machine will reclaim the object inside softreference.
The feature of SoftReference is that its example is preserved and quoted the soft of a Java object, and this soft existence of quoting does not hinder refuse collection thread to the recovery of this Java object.
That is, once after SoftReference saves and quote a Java object soft, before rubbish thread reclaims this Java object, the get () method that SoftReference class provides returns the strongly reference of Java object.In addition, once after rubbish thread reclaims this Java object, get () method will return null.
As a Java object, SoftReference object is preserved except the soft singularity quoted except having, and also has the generality of Java object.So, after soft reference object is recovered, although the get () method of this SoftReference object returns null, but this SoftReference object has no longer had the value of existence, need the purge mechanism that suitable, avoid the memory overflow that a large amount of SoftReference object brings.
Preferably, based on the list disposal route of buffer memory under Android platform of the present invention, in step S300, also comprise the steps:
Step S310, when establishment SoftReference object, employs a ReferenceQueue object is supplied to SoftReference building method as parameter:
ReferenceQueue queue=new ReferenceQueue();
SoftReference ref=new SoftReference(aMyObject,queue);
Step S320, when described SoftReference while the soft aMyOhject quoted reclaimed by garbage collector, the SoftReference object of ref institute strongly reference is put into ReferenceQueue.
In java.lang.ref bag, additionally provide ReferenceQueue, when establishment SoftReference object, employ a ReferenceQueue object is supplied to SoftReference building method as parameter:
ReferenceQueue queue=new ReferenceQueue();
SoftReference ref=new SoftReference(aMyObject,queue);
So when this SoftReference while the soft aMyOhject quoted reclaimed by garbage collector, the SoftReference object of ref institute strongly reference is put into ReferenceQueue.That is, preserve in ReferenceQueue to as if Reference object, and be lost it the Reference object of the soft object quoted.In addition as can be seen from this name of ReferenceQueue also, it is a queue, when we call its poll () method time, if in this queue be not empty queue, so will return that Reference object before queue.
At any time, the poll () method can calling ReferenceQueue check whether that it is concerned about non-by force can and object be recovered.If queue is empty, a null will be returned, otherwise the method returns a Reference object before in queue.Utilize this method, check which SoftReference the soft object quoted be recovered.These lose the SoftReference object of the soft object quoted dispose.
The operations such as access disk file, accesses network resource, Query Database are all the key factors affecting application program execution performance, if can again obtain quoting of those Java object be not yet recovered, unnecessary access will be reduced, greatly improve the travelling speed of program.
Analyze for scheme application in systems in practice below.
Need to be shown to list from the picture of the upper and lower medicine carrying product of network, and can often check this list.At this moment we have two kinds of program implementation usually: a kind of is that the just list checked in the past is kept in internal memory, and each life cycle storing the Java object of medicine information runs through whole application program all the time; Another kind is when user checks medicine list information at every turn time, the Java object storing current checked medicine information is terminated to quote, make refuse collection thread can reclaim memory headroom shared by it, when user needs to browse this list information again time, rebuild the information of this medicine.Obviously, the first implementation method will cause a large amount of internal memory wastes, even and if the defect that the second realizes is that refuse collection thread does not also carry out refuse collection, the object comprising medicine information is still kept in internal memory in good condition, and application program also will rebuild an object.
Based on the list disposal route of buffer memory under Android platform of the present invention, carry out L2 cache by the picture that will network be downloaded, saved flow, and improve the speed next time Showed Picture, improve Consumer's Experience, prevent internal memory to overflow simultaneously.
Finally it should be noted that obviously, those skilled in the art can carry out various change and modification to the present invention and not depart from the spirit and scope of the present invention.Like this, if these amendments of the present invention and modification belong within the scope of the claims in the present invention and equivalent technologies thereof, then the present invention is also intended to comprise these change and modification.

Claims (2)

1. under Android platform based on a list disposal route for buffer memory, it is characterized in that, comprise the steps:
Step S100, arranges two-level cache: first order buffer memory LinkedHashMap<String, Bitmap>; L2 cache ConcurrentHashMap<String, SoftReference<Bitmap>GreatT.G reaT.GT;
Step S200, first order buffer memory LinkedHashMap<String, Bitmap> retain the strongly reference of Bitmap, control the size MAX_CAPACITY=10 of buffer memory;
Step S300, when continuation is in this buffer memory when deposit data, least-recently-used element in level cache is put into L2 cache ConcurrentHashMap<String, SoftReference<Bitmap>GreatT.G reaT.GT, the soft of the Bitmap retained in L2 cache quotes SoftReference.
2. under Android platform according to claim 1 based on the list disposal route of buffer memory, it is characterized in that, described step S300 also comprises the steps:
Step S310, when establishment SoftReference object, employs a ReferenceQueue object is supplied to SoftReference building method as parameter:
ReferenceQueue queue=new ReferenceQueue();
SoftReference ref=new SoftReference(aMyObject,queue);
Step S320, when described SoftReference while the soft aMyOhject quoted reclaimed by garbage collector, the SoftReference object of ref institute strongly reference is put into ReferenceQueue.
CN201310684441.3A 2013-12-13 2013-12-13 Cache-based list processing method on android platform Pending CN104714897A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310684441.3A CN104714897A (en) 2013-12-13 2013-12-13 Cache-based list processing method on android platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310684441.3A CN104714897A (en) 2013-12-13 2013-12-13 Cache-based list processing method on android platform

Publications (1)

Publication Number Publication Date
CN104714897A true CN104714897A (en) 2015-06-17

Family

ID=53414252

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310684441.3A Pending CN104714897A (en) 2013-12-13 2013-12-13 Cache-based list processing method on android platform

Country Status (1)

Country Link
CN (1) CN104714897A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106055407A (en) * 2016-05-25 2016-10-26 努比亚技术有限公司 Process resource adjusting device and method
CN106802955A (en) * 2017-01-19 2017-06-06 济南浪潮高新科技投资发展有限公司 A kind of image data caching method
CN107908470A (en) * 2017-07-24 2018-04-13 广东电网有限责任公司信息中心 A kind of queried access method, apparatus and system based on CIM model

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010039609A1 (en) * 1997-08-22 2001-11-08 Koninklijke Philips Electronics N.V. Data processor with localised memory reclamation
US8161084B2 (en) * 2009-02-20 2012-04-17 Oracle America, Inc. Memory management of soft references
CN102541605A (en) * 2011-12-30 2012-07-04 Tcl集团股份有限公司 Method and device for picture loading based on Android system
CN103412825A (en) * 2013-05-21 2013-11-27 青岛海信移动通信技术股份有限公司 Internal storage releasing method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010039609A1 (en) * 1997-08-22 2001-11-08 Koninklijke Philips Electronics N.V. Data processor with localised memory reclamation
US8161084B2 (en) * 2009-02-20 2012-04-17 Oracle America, Inc. Memory management of soft references
CN102541605A (en) * 2011-12-30 2012-07-04 Tcl集团股份有限公司 Method and device for picture loading based on Android system
CN103412825A (en) * 2013-05-21 2013-11-27 青岛海信移动通信技术股份有限公司 Internal storage releasing method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张昊等: "Java软引用防止内存泄漏技术的研究", 《安徽教育学院学报》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106055407A (en) * 2016-05-25 2016-10-26 努比亚技术有限公司 Process resource adjusting device and method
CN106055407B (en) * 2016-05-25 2020-02-07 努比亚技术有限公司 Process resource adjusting device and method
CN106802955A (en) * 2017-01-19 2017-06-06 济南浪潮高新科技投资发展有限公司 A kind of image data caching method
CN107908470A (en) * 2017-07-24 2018-04-13 广东电网有限责任公司信息中心 A kind of queried access method, apparatus and system based on CIM model

Similar Documents

Publication Publication Date Title
CN1321377C (en) Method for controlling smart card storage environment
US11042477B2 (en) Memory management using segregated free lists
CN104699626B (en) Terminal internal memory processing method, device and terminal
US7840760B2 (en) Shared closure eviction implementation
CN103514102B (en) A kind of Java Virtual Machine realizes the method and device of internal memory garbage reclamation
TWI771332B (en) Resource recovery method and device
CN103473296A (en) Recycle bin mechanism and recycle bin system applicable to cloud computing
KR20040076048A (en) System and method for shortening time in compiling of byte code in java program
CN102541605A (en) Method and device for picture loading based on Android system
US10114765B2 (en) Automatic recovery of application cache warmth
EP2941707B1 (en) Shared and managed memory unified access
US20150058381A1 (en) System and method for dynamically selecting a garbage collection algorithm based on the contents of heap regions
US20020194210A1 (en) Method for using non-temporal stores to improve garbage collection algorithm
WO2001090899A2 (en) System and method for memory management using fixed-size blocks
CN111931095A (en) Picture loading method of Android system
CN104714897A (en) Cache-based list processing method on android platform
CN106649146A (en) Memory release method and apparatus
EP2941704B1 (en) Zero-copy caching
CN104216902A (en) Paging data loading method, device and system based on server paging
CN106406748A (en) Memory centric database architecture
CN111581157B (en) Object storage platform, object operation method, device and server
CN111125114A (en) Database horizontal extension method and device, and data table access method and device
CN109388459A (en) Picture loading method, device, computer equipment and storage medium
CN107330604A (en) The management method and system of air ticket air control rule
CN112230901A (en) Network programming framework system and method based on asynchronous IO model

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20150617

RJ01 Rejection of invention patent application after publication