<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.

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


    網站導航:
     
    主站蜘蛛池模板: 久久亚洲国产精品123区| 日韩不卡免费视频| 四虎影视永久免费观看网址| 亚洲激情视频图片| 成人毛片免费播放| 亚洲avav天堂av在线网毛片| 午夜免费福利在线观看| 亚洲av无一区二区三区| 国产91久久久久久久免费| 日本亚洲高清乱码中文在线观看| 国产黄色片在线免费观看| 精品在线观看免费| 亚洲综合日韩久久成人AV| 女同免费毛片在线播放| 久久久久亚洲精品无码蜜桃| 国产91免费在线观看| 亚洲xxxx18| 无码不卡亚洲成?人片| 中文在线免费不卡视频| 亚洲欧洲日韩国产综合在线二区| 最近中文字幕大全免费视频| 亚洲人和日本人jizz| 午夜神器成在线人成在线人免费| 久久亚洲精品11p| 久久精品亚洲乱码伦伦中文| 免费人成在线观看网站| 亚洲精品视频在线播放| 国产精品无码一二区免费| 国产精品福利在线观看免费不卡| 亚洲人成影院在线| 成年大片免费视频| 国产精品免费看久久久香蕉| 77777_亚洲午夜久久多人| 成人一a毛片免费视频| 国产成人无码免费网站| 亚洲一区二区三区首页| 日日夜夜精品免费视频| 中文字幕在线观看免费| 亚洲中文字幕一二三四区苍井空| 亚洲国产精品狼友中文久久久| 99re6热视频精品免费观看|