使用大量的记忆资源 [英] using much memory resourses

查看:97
本文介绍了使用大量的记忆资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码有什么问题?它似乎使用了大量的内存资源。因为当它第二次运行时,打开文件对话框无法正常工作。请提前帮助我。谢谢。

what's problem whit this code? it seem's uses much memory resource. because when it runs for second time , the open file dialog does not work properly.please help me.thanks in advance.

 Try

    If OpenFD.ShowDialog = Windows.Forms.DialogResult.OK Then
        PictureBox3.Image = Image.FromFile(OpenFD.FileName)

        Dim NewSize As New Size(800, 600)
        ResizedImage = New Bitmap(PictureBox3.Image, NewSize)
        PictureBox3.Image = ResizedImage
        PictureBox3.BackgroundImageLayout = ImageLayout.Stretch
    End If

    If PictureBox3.Image Is Nothing Then
        Exit Sub
    End If

    Dim i As Integer = Me.Panel2.Controls.Count - 1
    Dim x1 As Integer
    Dim y1 As Integer
    If i = -1 Then
        x1 = Panel2.Location.X + 10
        y1 = Panel2.Location.Y + 10
    Else
        x1 = Panel2.Controls(i).Location.X + 110
        y1 = Panel2.Controls(i).Location.Y
    End If

    If x1 < Panel2.Width - 50 Then
        x1 = Panel2.Location.X + 10
        y1 = Panel2.Controls(i).Location.Y + 110
    End If
    Dim ctlLocation As New Point(x1, y1)
    Dim ctrl As New PictureBox
    ctrl.Image = PictureBox3.Image
    ctrl.Location = ctlLocation
    ctrl.Size = New Size(100, 100)
    ctrl.SizeMode = PictureBoxSizeMode.StretchImage
    ctrl.BorderStyle = BorderStyle.FixedSingle
    Me.Panel2.Controls.Add(ctrl)
    PictureBox3.Image = Nothing

    AddHandler ctrl.Click, AddressOf ClickHandler1
Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "بروز خطا،لطفا دوباه سعی کنید")
End Try

推荐答案

你通过这段代码放了多少张图片?导致此错误的代码没有任何问题,但如果您通过它放置了几百个图像,它似乎为每个图像创建一个新的PictureBox控件。这会导致严重的问题,因为您无法在表单上拥有无限数量的控件,并且会占用大量内存。
How many images are you putting through this code?? There is nothing wrong with the code that would cause this error, but if you were putting a couple hundred images through it, it appears to create a new PictureBox control for every image. This will cause you severe problems as you cannot have an unlimited number of controls on a form and it will consume a large amount of memory.


这篇关于使用大量的记忆资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆