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
-
呢幾日開始有少少忙嘅感覺,但係忙埋呢幾日,就可以去個 Short Trip. 反正離歐洲咁近,有時間都應該去吓唔同國家。 按照劇本,於工之後吃完飯休息一陣就去咗做 Gym, 聽日夜晚返到屋企就要執行李,星期五放工直接去 Crawley 留一晚,第二朝再飛。 前幾日秋分,唔...
-
字裏行間,就可以見到香港良心同民主之父嘅分別。 新聞穚 10月19日 陳方安生:恢復立法會的尊嚴和權威 雖然我身在外地,但仍密切關注香港發生的大事。我曾經是地區直選產生的立法會議員,看到10月15日行政長官宣讀施政報告過程中,某些直選議員的行為,我實在震驚。假如他們以為藉著這種不...
-
唔知點解,好似年年都會寫,明明唔想寫,但係又偏偏俾我搵到另一個解度去寫。本來只係想 Post 一句 Status, 但越諗越多嘢,都係想寫場出嚟。 話說呢排 Les Misérables 嘅其中一幕《Do you hear the people sing》嘅中文版好 hit,...
-
預 料 鰂 魚 涌 的 海 水 高 度 會 在 早 上 (8 月 5 日 ) 6 時 至 10 時 期 間 上 漲 至 海 圖 基 準 面 以上 2.9 米 , 海 水 上 漲 可 能 會 引 致 上 環 低 窪 地 區 出 現 水 浸 。 點解唔直接講「預料本港水域海水高度.....
-
一早起身執嘢 Check-out, 唔想食亦都唔識叫日式早餐,決定去麥記食個早晨全餐,本來嘗試用英文叫 Big Breakfast, 但店員好似唔係太識聽。佢指一指櫃枱上面個 Menu, 咁我就指個早晨全餐,Mission Completed。 個早晨全餐好掂,首先杯橙汁唔...
-
英國政黨政治嘅 life cycle: 一個做咗好耐嘅首相,因某些事失去民眾支持宣佈辭職 同一個黨會有一個新首相,但唔會做得長 政黨輪替 返回第一步
-
今日,原來諗住影億萬像素嘅全景圖,但係一來天氣唔太好,二來唔知點解返到屋企先知,第一行嘅相唔見咗,唯有下次得閒再影。 好彩影咗單行香港島嘅 Skyline 做後備,唔係嘅話真係 Total Lost 跟手見到個鴨頭,就影多幅有隻鴨嘅全景圖 不過嚟同走嗰...
-
沒有人可以認識所有事物,但有些事,你總會認識。 十幾年前,唔睇足球嘅,個個都識碧咸。而世界上有好多知名相片,當中嘅歷史背景大家可能都唔知。時代雜誌响2016年選出 100 Photographs: The Most Influential Images of All Time...
-
之前一日被通知,班機 Delay 咗兩個鐘,都好,唔使太早去機場。Check-in 嘅時候,就俾咗張 Coupon 買嘢食 入咗閘後,去咗大家樂,買咗個荷葉飯餐,一支水,重有錢剩,就買多杯 Yogurt, 重有5蚊剩,但係無計較得咁多,太多嘢食唔晒就無謂。個荷葉飯啲蝦米就略...
-
節錄明報一連兩日有關母語教學嘅報道 10月31日 「你認為下列哪一位母親最值得表揚?孟子的母親、岳飛的母親、《遊子吟》中的慈母?試討論並達成共識。」考試及評核局 的報告揭示,不少高級程度會考生對這3名人物一竅不通,甚至對《遊子吟》聞所未聞,報告形容對考生中文科水平「大感詫異...
No comments:
Post a Comment