<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    rednight

    0x2B|~0x2B,That's not a question,Just do it.
    posts - 32, comments - 14, trackbacks - 0, articles - 0

    Memory Leak for ListCellRenderer

    Posted on 2007-01-16 09:04 rednight 閱讀(432) 評論(0)  編輯  收藏

    We have known, the ListCellRenderer interface has only one method public Component getListCellRendererComponent(), and it returns a Component. When a JList needs to compute its dimension or paint its cell item, this method will be called. So it will be called frequently, and we have a best practice, try to reuse object, avoid time-consumed computation and unnecessary operation in this method.

    ?

    Recently found, there is a memory leak bug for list cell renderer in both JDK 1.4.x and JDK 5 (don’t know whether has the same bug in earlier JDK). The component returned from getListCellRendererComponent() method could not be GC, and all its referenced objects also could not be GC. Unfortunately, this bug is only fixed in JDK 6.

    ?

    So currently, if a JList use the ListCellRenderer, but only holds a little resource (eg: the JList only has little items, and the component is returned from ListCellRenderer is a simple JLable), you may not care about the memory leak.

    ?

    But if a JList use the ListCellRenderer, and holds a large resource, you should remember to use the following way to avoid memory leak.

    ?

    Work Around: Subclass JList and invoke removeAll after painting is done:

    ?????? public class xxxList extends JList {

    ??????????? private CellRendererPane renderer;

    ??????????? private CellRendererPane getRenderer() {

    ??????????????? if (renderer == null) {

    ??????????????????? for (int i=0; i<getComponents().length; i++) {

    ????????????????????????????????????????? Component c? = getComponents()[i];

    ??????????????????????? if (c instanceof CellRendererPane) {

    ??????????????????????????? renderer = (CellRendererPane)c;

    ??????????????????????????? break;

    ??????????????????????? }

    ??????????????????? }

    ??????????????? }

    ??????????????? return renderer;

    ??????????? }

    ??????????? protected void paintComponent(Graphics g) {

    ??????????????? super.paintComponent(g);

    ??????????????? CellRendererPane renderer = getRenderer();

    ??????????????? if (renderer != null) {

    ??????????????????? renderer.removeAll();

    ??????????????? }

    ??????????? }

    ??????? }


    Please refer to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5044798 for more details.

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 大妹子影视剧在线观看全集免费| 午夜无码A级毛片免费视频| 亚洲AⅤ男人的天堂在线观看| 美女被免费视频网站a| 你是我的城池营垒免费观看完整版| 一级毛片**不卡免费播| 狠狠色婷婷狠狠狠亚洲综合 | 小草在线看片免费人成视久网| 亚洲精品综合久久| 亚洲图片中文字幕| 国产免费人成视频尤勿视频 | 一个人免费观看日本www视频| 88xx成人永久免费观看| 国产99视频精品免费视频7| 久久久亚洲欧洲日产国码aⅴ| 亚洲国产高清国产拍精品| 黄色免费在线网站| 免费国产成人高清视频网站| 亚洲免费观看网站| 免费无码一区二区三区蜜桃| 国产无遮挡吃胸膜奶免费看| 亚洲日韩乱码中文无码蜜桃臀| 18以下岁毛片在免费播放| 亚洲国产女人aaa毛片在线| 免费无码一区二区三区蜜桃| 激情内射亚洲一区二区三区| 无码国产精品一区二区免费| 亚洲无线观看国产精品| 亚洲av成人中文无码专区| 亚洲午夜精品久久久久久浪潮 | 日韩在线播放全免费| 亚洲一区综合在线播放| 蜜桃视频在线观看免费网址入口| 亚洲黄色中文字幕| 精品无码无人网站免费视频| 99久久国产亚洲综合精品| 久久久久国产精品免费免费搜索| 老司机午夜免费视频| 亚洲精品乱码久久久久久下载| 在线美女免费观看网站h| 亚洲av无码成人影院一区|