<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 閱讀(437) 評論(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.

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲AV无码久久精品色欲| 日韩视频在线免费观看| 最近的中文字幕大全免费8| 成熟女人牲交片免费观看视频 | 国产精品V亚洲精品V日韩精品 | 最近中文字幕无吗免费高清| ww亚洲ww在线观看国产| 日本zzzzwww大片免费| 成人男女网18免费视频| 亚洲av日韩av无码av| 国产91色综合久久免费| 亚洲人成www在线播放| 免费羞羞视频网站| 美女视频黄频a免费大全视频| 免费一级毛片免费播放| 亚欧乱色国产精品免费视频| 亚洲愉拍99热成人精品热久久 | 成人无码WWW免费视频| 亚洲国产综合专区在线电影| 亚洲乱人伦精品图片| 成人激情免费视频| 老司机免费午夜精品视频| 亚洲午夜av影院| 日韩视频在线观看免费| 亚洲一级黄色大片| 国产成人免费网站在线观看| 一级成人a做片免费| 亚洲影院在线观看| 日韩免费a级在线观看| 中国一级全黄的免费观看| 91在线精品亚洲一区二区| 好吊妞视频免费视频| 久青草视频在线观看免费| 亚洲福利电影在线观看| 狠狠久久永久免费观看| 中文字幕在线观看免费| ass亚洲**毛茸茸pics| 国产亚洲精品影视在线产品| 成人免费大片免费观看网站| 人妻仑乱A级毛片免费看| 亚洲国产日韩在线一区|