对。如果对内存要求比较严格,最好不要用csharp :)

解决方案 »

  1.   

    对象的删除:
    有几种数据类型对于调用函数Disponse()是非常重要的,如:
    Graphics,Pen,Brush...
    或使用using结构。
    //绘制图像
    Graphics g=e.Graphics;
    // g.DrawImage(theImage,ClientRectangle);
    g.FillRectangle(Brushes.White,ClientRectangle);
    Brush tBrush=new TextureBrush(smallImage,new Rectangle(0,0,smallImage.Width,smallImage.Height));
    //Pen tPen=new Pen(tBrush,15);
    Font trFont=new Font("Times New Roman",32,FontStyle.Bold|FontStyle.Italic);
    g.DrawString("Hello Image",trFont,tBrush,ClientRectangle);
    //g.DrawRectangle(tPen,20,20,240,240);
    //g.FillEllipse(tBrush,ClientRectangle);
    //tPen.Dispose();
    trFont.Dispose();
    tBrush.Dispose();
      

  2.   

    To newhacker21cen(碇 真治):
    ksec() 说的应该是当你需要某个对象时,就new一个,用完就释放掉(Dispose,etc.)
      

  3.   

    .net framework 中内存的分配和释放是由无用内存回收器负责。每次我们使用new操作符创建对象时,clr会在managed heap中分配内存的。当内存不够时,无用内存回收器就还是回收,释放不用了的内存。但是我们知道析构方法性能较差。
       所以我们可以用强制回收方法Close()和Dispose()。当然当我们不能肯定用户能否调用Dispose()时,可以用using语句保证Dispose()会在语句退出时调用。
      

  4.   

    请问怎么使用using语句保证Dispose()会在语句退出时调用?
      

  5.   

    打个比方:using(Font theFont = new Font("ab",10.0f))
    {
       //这里使用theFont
    }  //using语句结束时,编译器将调用hteFont的Dispose();其实就是相当于一个try{}catch{}块