A few mon, I have encountered a quite disturbing problem (see below). Until recently, I found that this problem can be solved by a interesting class, SoftReference, in Java. So, I formulated the following pattern. It's still a rough draft, but I would like to publish it first.
Name: Self-disposing Resource Pattern (Java)
Context: A is some expensive resource that may or may not be pooled. A is used to create another kind of resource, B. If A is disposed, it cannot create B anymore. However, if A is not disposed, the system may run out of memory.
Problem: Determine when to dispose A.
Solution: Java comes with SoftReference class for memory management. “An object is softly reachable if it is not strongly reachable but can be reached by traversing a soft reference.” An A instance can be registered to a resource manager to be a soft reference when it is no longer reachable by any thread. On the other hand, the resource manager can start off a thread to dequeue the SoftReference instances from a reference queue and clean up the resource properly.
Search This Blog
Subscribe to:
Post Comments (Atom)
Popular Posts
-
話說古有新安八景,香港有二,一為杯渡禪蹤,二為鰲洋甘瀑。熙時年間嘅《新安縣志》曰:「鰲洋甘瀑在七都大洋中。有石高十丈,四面鹹潮。中有甘泉飛瀑,若自天而下。」 鰲洋甘瀑今位於南區薄扶林瀑布灣,搭車去華富邨行一陣就到。 香港開埠前,英國外科醫生及博物學家 Clarke Abe...
-
用咗 HTC Touch 都有 3 年幾,係買俾自己嘅生日禮物。呢三年有樣嘅好不滿嘅係打字嘅方法,個手寫識辨又唔似 Palm 嘅 Graffiti 咁可以唔駛睇住都寫到字,個 software keyboard 又細,要用 stylus 打先打到,重要支 stylus 鬼咁易爛,...
-
精神緊張之下,只係瞓咗6個鐘,要去拎錢同 Passport Application Form, 行去 Gloucester Road 站,去郵局攞好 Form. 間郵局係响一間鋪頭入面,而間鋪頭咁啱有 Western Union 嘅 Agent, 問題只係無 Passport, ...
-
香港有 TEDx, 都想睇好耐,難得小雲都有興趣,就一齊去睇吓咁。當中畢明爆咗幾句金句: 啲 PowerPoint 嘅內容,又無 Power, 又無 Point Comfort Zone, 即係你覺得 Comfort 就要鬆 第一個 Session 就 Ove...
-
Facebook 嘅唯一用處,係觀察各人嘅關係,會有一 D 意想不到嘅發現。包括你嘅中學同學係識得你嘅小學同學。
-
好耐未試過成個人休克,對上一次好似係十年前左右做第一份工,返到屋企小解完就突然間感覺唔到心跳,到有知覺嘅時候,個下巴好痛,似乎就係撞咗落咗個馬桶度。 今日做 Gym 嗰陣,只係好簡單咁提腿收腹,只係做咗一 Set, 又係感覺唔到心跳,知自已就暈,但已經做唔到啲乜,到有知覺嘅時...
-
前幾晚開始搵邊度有地方跳剔撻舞,見到星期日有兩堂街舞課,於是就㨂咗其中一堂去玩吓。因為天雨關係,攪到地鐵部份地方水浸,於是要轉巴士去 Studio 度。去到之後,交好入會費,就等上堂。 又係天雨,導師遲到,又上一堂嘅導師幫手熱咗身先,一個鐘頭,轉睇間就過去,可能因為係初級班...
-
响地鐵走出嚟,聽到一堆人响到講點行點行,點解唔搭的士云云。於是問一問佢哋想去邊,想去「富臨」喎... 聽落好熟,但係唔太記得响邊,跟住佢哋問上環街市响邊,指咗個方向之後,佢哋已經行開咗。過多幾秒,先記得原來富臨就係屋企對面間酒樓,即係話呢間酒樓,對於我呢個老街坊嚟講,似乎唔係...
-
The plan of the coming Saturday: 1. Booking Ski Trip 2. Go to bank with Mom 3. Take suit to Father's shop 4. Get a pair of new glasses 5...
No comments:
Post a Comment