M
mycwcgr_new
Unregistered / Unconfirmed
GUEST, unregistred user!
对于PictureBox1.Image=Image.FromStream(stream),因为在 Image 对象的生存期内,必须使流保持为打开,是否会内存泄露 ( 积分: 10 )<br />对于PictureBox1.Image=Image.FromStream(stream),因为在 Image 对象的生存期内,必须使流保持为打开,是否会内存泄露
下面Display()是会被反复大量的调用,因为在Image 对象的生存期内,必须使流保持为打开(MSDN的原文),所以不能执行stream.Close();
这样是否会产生内存泄露?会有什么严重后果?
namespace MultiMediaView
{
/// <summary>
/// DatabasePicture 的摘要说明。
/// </summary>
public class DatabasePictureicture
{
private ResourceData myResourceData;
public DatabasePicture(PicturePar myPicturePar,ResourceData myResourceData):base(myPicturePar)
{
this.myResourceData=myResourceData;
}
public override void Display()
{
MemoryStream stream=new MemoryStream();
try
{
byte[] myCotent=myResourceData.content;
stream.Write(myCotent,0,myCotent.Length);
stream.Position=0;
myPicturePar.myPicture.Image=Image.FromStream(stream);
}
finally
{
//在 Image 对象的生存期内,必须使流保持为打开。
}
}
}
}
下面Display()是会被反复大量的调用,因为在Image 对象的生存期内,必须使流保持为打开(MSDN的原文),所以不能执行stream.Close();
这样是否会产生内存泄露?会有什么严重后果?
namespace MultiMediaView
{
/// <summary>
/// DatabasePicture 的摘要说明。
/// </summary>
public class DatabasePictureicture
{
private ResourceData myResourceData;
public DatabasePicture(PicturePar myPicturePar,ResourceData myResourceData):base(myPicturePar)
{
this.myResourceData=myResourceData;
}
public override void Display()
{
MemoryStream stream=new MemoryStream();
try
{
byte[] myCotent=myResourceData.content;
stream.Write(myCotent,0,myCotent.Length);
stream.Position=0;
myPicturePar.myPicture.Image=Image.FromStream(stream);
}
finally
{
//在 Image 对象的生存期内,必须使流保持为打开。
}
}
}
}