亚洲免费av电影一区二区三区,日韩爱爱视频,51精品视频一区二区三区,91视频爱爱,日韩欧美在线播放视频,中文字幕少妇AV,亚洲电影中文字幕,久久久久亚洲av成人网址,久久综合视频网站,国产在线不卡免费播放

        ?

        The Research on building cache for Android platform using soft references

        2013-04-29 03:43:54YongpanShengRuitingDai
        無(wú)線互聯(lián)科技 2013年7期
        關(guān)鍵詞:研究

        Yongpan Sheng Ruiting Dai

        Abstract:Along with the mobile platform increasing development,Android operating system has become the dominant operating system on mobile platforms.As the result of the limitation of Android system computing environment and network resources,it is especially important to apply Cache technology to improve the efficiency of data access.In this paper,a detail study is made on soft reference technology of mobile platform and soft reference strategy is proposed to build a cache on the Android platform application.It has increased the use of system memory efficiently and data access performance.Meanwhile soft reference object can help the Dalvik virtual machine to manage memory and eliminate potential memory leaks well.

        Keyword:Android;Soft Reference;Cache

        In the Android System Computing Environment, system memory and the bandwidth of the wireless communication is very limited.This requires that the Android client should try to reduce the commnunication overhead over the wireless and conservation memory resources when in use. Caching techniques, as the classical techniques of improving data access performance, have achieved successful application in the field of computer communication[1]. When introduced Caching techniques into the Android mobile computing environment,it is conducive not only to reduce the overhead of the Android client in the wireless communication procedure, but also to improve the hit rate of the valid data in the memory.

        Soft references is a high level of Java objects. It is very suitable for creating the cache to store some expensive common resources in the Android client environment.The client can check the availability of the cached data before performing query operations[2].In general,data can be directly obtained in the repetitive operations.While data out of the range of cache management need to be loaded asynchronously over wireless network.

        1 The characteristics of soft references

        A soft reference is the object referenced by SoftReference with a relatively long life cycle.In the Android environment,only when system is starved of memory will it release the soft reference object.So we can use them to store some expensive resources which need to be loaded asynchronously,such as online picture data in which each soft reference object that has stored picture data existing in the entire application lifecycle is also a java object[3]. Besides,when the system is out of memory,the content cached by soft reference can be released and recycled by Dalvik virtual machine.

        Dalvik virtual machine often perform garbage collection operations according to Mark-Sweep algorithm, which causes the uncertainty of running time. However,provided that the a object which reference exists will be in the memory all the time.If more and more objects like this exist,which even beyond the memory capacity of Dalvik virtual machine,the system will throw OOM(Out of Memory) error.It is more flexible to control the lifecycle of less important object in the application through soft references.When the system is out of memory,these objects can be recycled temporarily.If the system memory is also lacking after the Dalvik virtual machine has finished all the recycling project,the Dalvik will throw OOM error.

        2 The management of soft references

        We can flexibly control the liftcycle of Java object in the application with soft references.The method of using it is shown in Java code below:

        MyObject ref=new MyObject();//Create an object of type MyObject

        SoftReference softRef=new SoftReference(ref);//Create a soft reference of ref object

        ref=null;//Eliminate the strong reference to the MyObject object

        MyObject anthorRef=(MyObject)softRef.get();

        //Obtain the object through soft reference

        After executing the above code,there are two ways to reference the MyObject object.One is for the soft reference of softRef and the other one is for the strong reference of ref means MyObject object is a strongly reachable object.When the ref is set to null,the garbage collection thread in the Dalvik will make a distinction between softly reachable object and other strongly reachable object in the system. Whats more,before the Dalvik throws OOM,the garbage collection thread would recycle the unused softly reachable object as preferentially as possible. And the Dalvik will reserve the newly created softly reachable object as much as possible.Before recycling the MyObject object,the get() method of softRef obtains the strongly reference of MyObject object. And after recycling,the get() method returns null[4].

        Besides the particularity of soft reference object,SoftReference object has the generality of Java object.When the softly reachable object reclaimed, this SoftReference object is already not worthy to exist although the get() method of SoftReference object returns null.That is because the soft reference object it keeps has alreay not existed. At this time,an appropriate clearance mechanism is needed to avoid the “new” memory leaks caused by a large number of SoftReference objects.The Java.long.ref package provides ReferenceQueue object.The methods of using it is shown in Java code below:

        ReferenceQueue refQueue=new ReferenceQueue();//Create a reference queue

        SoftReference softRef=new SoftReference(ref,refQueue);

        //Add the soft reference into the reference queue

        while(null !=(refQueue.poll())){

        // clear ref object

        }

        After executing the above code,with the soft reachable object stored by this SoftReference object being recycled by Dalvik garbage collection thread,SoftRefrence object referenced by softRef is added to ReferenceQueue[5].ReferenceQueue is a queue, which stores SoftReference objects that lost reference object.This queue has the characteristic of “FIFO”.We can call the poll() method to check whether the soft reference objects it concerns is recycled or not. If the queue is empty, it returns null,otherwise it returns a SoftReference object at the head of the queue. Meanwhile we can check which SoftReference has been recycled and then clean up the SoftReference objects which lost reference object.

        3 The implementation strategy of soft reference cache in Android platform application

        In the Android application of C/S structure,the client usually needs to obtain pictures and other data information from the server.However,loading pictures is a time consuming and traffic consuming process.If the issue is not properly handled,it will make users feel stuck and the application is not friendly.There may be a lot of repetitive operations when loading pictures. From this angle embarking, there is no need to refetch the network pictures from the same URL address.We can keep some expensive image resources in memory and use LRU algorithm to optimize storage.Besides,the other image resources can be saved in the SDCard of client.As the pictures take up only a little space in the SDCard,it not only ensures the speed of loading pictures but also saves the traffic of the wireless communication. This caching strategy applys to the asynchronous image loading by ListView.Moreover,It can futher optimize memory allocation and better avoid throwing ANR(Application Not Responsed) exception information by the application,which is good for the interaction with users.The specific implementation can be divided into several steps below:

        (1)Create buffer cache in memory.We can use LinkedHashMap to create strongly reference cache used to store URLs of network pictures and corresponding Bitmap objects.Because LinkedHashMap store data in the bottom,it has a higher efficiency to access data. ConcurrentHashMap is used to store URLs of pictures and corresponding Bitmap soft reference objects,which has a guarantee for synchronizing data and accessing safely to threads.

        (2)The implementation of load pictures asynchronously.Android provides AsyncTask class which encapsulate basic models used in asynchronous operations.We can execute pictures request operation in doInBackground() method.After loading,the AsyncTasks built-in handler send message to main thread and all the UI operation achieved in onPostExecute() method.

        (3)Design callback and execute LRU replacement algorithm.Two methods is needed to included in designed callback interface.One is for pass URLs of pictures and loaded Bitmap objects to UI thread,the other one is for replace inactive picture resource in strongly reference cache to soft reference cache through executing LRU algorithm.

        We can achieve ListView loading network pictures asynchronously with cache,those concrete procedures are as shown below.

        4 Conclusion

        Soft references, which have strong reference function,can be used in the Android computing environment with limited system memory and wireless broadband to cache some expensive resources that need to be loaded asynchronously.It can improve the utilization of memory and the performance of accessing data.This paper focuses on the characteristics and management methods of soft references.For the Android platform application, the implementation strategy of soft reference in loading pictures asynchronously by ListView is proposed. There is still one thing should be concerned that although soft reference can control the life cycle of Java object in the application flexibly,it may not effective to android client application which is very dependent on cache in performance.Furthermore,it cannot replace complex caching framework that can provide flexible termination period.

        [References]

        [1]張昊,潘祖烈.Java軟引用防止內(nèi)存泄漏技術(shù)的研究[J].安徽教育學(xué)院學(xué)報(bào),2006,24(6):42-45.

        [2]楊安寧,周瑩,呂康,等.一種Android平臺(tái)GIS軟件的新型數(shù)據(jù)緩存策略的實(shí)現(xiàn)[J].計(jì)算機(jī)與現(xiàn)代化,2012,(10):46-49.

        [3]焦忭忭.移動(dòng)數(shù)據(jù)庫(kù)在管理信息系統(tǒng)中的應(yīng)用研究[D].武漢理工大學(xué),2006.

        [4]曾麗娟,婁松濤.移動(dòng)客戶機(jī)中緩存技術(shù)的應(yīng)用研究[J].電腦知識(shí)與技術(shù)(學(xué)術(shù)交流),2007,3(18):1657-1658.

        [5]周毅敏,陳榕.Dalvik虛擬機(jī)進(jìn)程模型分析[J].計(jì)算機(jī)技術(shù)與發(fā)展,2010,20(2):83-86.

        猜你喜歡
        研究
        FMS與YBT相關(guān)性的實(shí)證研究
        2020年國(guó)內(nèi)翻譯研究述評(píng)
        遼代千人邑研究述論
        視錯(cuò)覺(jué)在平面設(shè)計(jì)中的應(yīng)用與研究
        科技傳播(2019年22期)2020-01-14 03:06:54
        關(guān)于遼朝“一國(guó)兩制”研究的回顧與思考
        EMA伺服控制系統(tǒng)研究
        基于聲、光、磁、觸摸多功能控制的研究
        電子制作(2018年11期)2018-08-04 03:26:04
        新版C-NCAP側(cè)面碰撞假人損傷研究
        關(guān)于反傾銷會(huì)計(jì)研究的思考
        焊接膜層脫落的攻關(guān)研究
        電子制作(2017年23期)2017-02-02 07:17:19
        亚洲国产a∨无码中文777| av手机在线天堂网| av永远在线免费观看| 日本亚洲中文字幕一区| 亚洲av网一区二区三区| 牛鞭伸入女人下身的真视频| 亚洲公开免费在线视频| 91热久久免费频精品99| 亚洲第一女人av| 无码人妻精品一区二区三区不卡| 91av视频在线| 亚洲麻豆av一区二区| 亚洲中文字幕舔尻av网站| 国产成人av大片大片在线播放 | 中文字幕日韩精品亚洲精品| 最近免费中文字幕中文高清6 | 美女脱了内裤露出奶头的视频| 97精品一区二区视频在线观看| 久久噜噜噜| 性色av一区二区三区密臀av| 亚洲码欧美码一区二区三区| 国产av电影区二区三区曰曰骚网| 免费一级国产大片| 高清中文字幕一区二区三区| 国产美女精品视频线免费播放软件 | 日本韩国三级在线观看| 含紧一点h边做边走动免费视频 | 欧美激情视频一区二区三区免费| 亚洲aⅴ天堂av天堂无码麻豆| 国产自产av一区二区三区性色| 中文字幕日韩精品人妻久久久| 日本久久久久亚洲中字幕| 国产亚洲精久久久久久无码77777 丝袜足控一区二区三区 | 高清偷自拍第1页| 国产成人精品日本亚洲专区6| 久久久国产熟女综合一区二区三区 | 蜜桃国产精品视频网站| 亚洲av色香蕉一区二区三区老师| 无码国产精品一区二区免费16| 亚洲av网站首页在线观看| 激情综合五月开心婷婷|