<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) 評(píng)論(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.

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 伊人久久免费视频| 国产在线观a免费观看| 亚洲午夜在线一区| 91亚洲国产成人久久精品网址| 在线免费播放一级毛片| 日本最新免费网站| 成人国产mv免费视频| www亚洲精品少妇裸乳一区二区| 亚洲爽爽一区二区三区| 99久久精品国产亚洲| 亚洲日本VA午夜在线电影| 日韩电影免费在线观看网址 | 久久夜色精品国产噜噜亚洲a| 久久亚洲中文字幕无码| 久操免费在线观看| 免费欧洲美女牲交视频| 亚洲精品视频观看| 免费国产在线视频| 亚洲国产成人VA在线观看| 国产成人精品日本亚洲专| 一级做a免费视频观看网站| 91网站免费观看| 亚洲熟妇中文字幕五十中出| 亚洲1区1区3区4区产品乱码芒果| 成人免费一区二区三区 | 日产乱码一卡二卡三免费| 免费在线观看亚洲| 国产在线jyzzjyzz免费麻豆| 一本色道久久88亚洲精品综合| 99久久久国产精品免费牛牛四川 | 亚洲精品无码久久久久久久 | 亚洲精品第一国产综合亚AV| 24小时日本电影免费看| 九月丁香婷婷亚洲综合色| 精品久久久久亚洲| 日韩免费视频一区| 中出五十路免费视频| 亚洲一本之道高清乱码| 亚洲国产V高清在线观看| 中文字幕免费视频| 亚洲精品成人久久|