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

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


    網站導航:
     
    主站蜘蛛池模板: 中文亚洲成a人片在线观看| 在线a毛片免费视频观看| 亚洲日本在线观看视频| 香蕉视频在线观看免费| 四虎成人免费大片在线| 亚洲精品永久在线观看| 日韩精品视频免费网址| 亚洲狠狠婷婷综合久久| 日韩视频免费在线| 特级做a爰片毛片免费看| 亚洲欧洲日产国码无码网站| GOGOGO免费观看国语| 久久精品国产亚洲| 亚洲美女视频免费| 亚洲一区二区三区精品视频| 成年美女黄网站18禁免费| 亚洲av色香蕉一区二区三区| 亚洲Av无码乱码在线znlu| 福利免费在线观看| 亚洲丝袜美腿视频| 国拍在线精品视频免费观看| 亚洲AV无码一区二区三区久久精品| 免费大片黄手机在线观看| 久久精品无码专区免费| 亚洲视频在线观看| 国产性生交xxxxx免费| 一区二区三区免费电影| 亚洲va久久久噜噜噜久久男同| 67pao强力打造国产免费| 亚洲人成电影网站免费| 亚洲视频在线免费| 69pao强力打造免费高清| 亚洲国产精品成人综合色在线| 亚洲国产一级在线观看| 人妻无码久久一区二区三区免费 | 18禁免费无码无遮挡不卡网站| 亚洲中文无码亚洲人成影院| 亚洲中文字幕成人在线| 18禁黄网站禁片免费观看不卡| WWW亚洲色大成网络.COM | 免费观看美女用震蛋喷水的视频|