如何减少C#程序的内存消耗? 对。如果对内存要求比较严格,最好不要用csharp :) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对象的删除:有几种数据类型对于调用函数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(); To newhacker21cen(碇 真治):ksec() 说的应该是当你需要某个对象时,就new一个,用完就释放掉(Dispose,etc.) .net framework 中内存的分配和释放是由无用内存回收器负责。每次我们使用new操作符创建对象时,clr会在managed heap中分配内存的。当内存不够时,无用内存回收器就还是回收,释放不用了的内存。但是我们知道析构方法性能较差。 所以我们可以用强制回收方法Close()和Dispose()。当然当我们不能肯定用户能否调用Dispose()时,可以用using语句保证Dispose()会在语句退出时调用。 请问怎么使用using语句保证Dispose()会在语句退出时调用? 打个比方:using(Font theFont = new Font("ab",10.0f)){ //这里使用theFont} //using语句结束时,编译器将调用hteFont的Dispose();其实就是相当于一个try{}catch{}块 菜鸟求助来了!实在想不明白了! 在c#中如何在WINDOWS FORM 中访问超级链接? 怎么把一个文件转换为postgreSQL的逃逸字符串啊? 两条512M组成双通道快还是一条512M加一条1G快? asp.net 剔除出了换行以外的其他html标签 一个frame页面的问题。 数组? 为啥web应用程序中无法使用全局变量? 使用Access数据库时,为什么不能用update更新记录 C#在IIS创建网站的时候怎么设置默认的ASP.NET版本 请问:如何开始制作用户自定义的web control? 关于XML 解析器的选择
有几种数据类型对于调用函数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();
ksec() 说的应该是当你需要某个对象时,就new一个,用完就释放掉(Dispose,etc.)
所以我们可以用强制回收方法Close()和Dispose()。当然当我们不能肯定用户能否调用Dispose()时,可以用using语句保证Dispose()会在语句退出时调用。
{
//这里使用theFont
} //using语句结束时,编译器将调用hteFont的Dispose();其实就是相当于一个try{}catch{}块