Click here to Skip to main content
15,917,455 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionGarbage Collection Pin
KSR816-Oct-09 12:57
KSR816-Oct-09 12:57 
AnswerRe: Garbage Collection Pin
raghu.g6-Oct-09 17:56
raghu.g6-Oct-09 17:56 
AnswerRe: Garbage Collection Pin
N a v a n e e t h6-Oct-09 18:03
N a v a n e e t h6-Oct-09 18:03 
AnswerRe: Garbage Collection Pin
supercat97-Oct-09 7:44
supercat97-Oct-09 7:44 
GeneralRe: Garbage Collection Pin
KSR817-Oct-09 11:15
KSR817-Oct-09 11:15 
QuestionNCoverExplorer Report & MSBuild Pin
Jammer6-Oct-09 10:48
Jammer6-Oct-09 10:48 
AnswerRe: NCoverExplorer Report & MSBuild [modified] Pin
Ergwun9-Jun-10 21:18
Ergwun9-Jun-10 21:18 
QuestionMemory leak in VB.NET screenshot application Pin
Jordan19826-Oct-09 4:10
Jordan19826-Oct-09 4:10 
Good afternoon,

I am hoping somebody can help me with a screenshot application I am developing that has a memory leak somewhere.

The main code is as follows:

Private Sub Main()
    Try
        ScreenShot()
        If ScreenShot() = True Then
            'Calls a sub that raises an outlook email with the screenshot attached
            OutlookEmail()
            'This try statement will delete the temporary file created with an image of the screenshot
            'This is quicker than using the clipboard and will not affect anything already on there
            Try
                If System.IO.File.Exists(strPath) Then
                    System.IO.File.Delete(strPath)
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        Else
            MessageBox.Show("Failed to take a screenshot - please report to helpdesk")
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub
Private Function ScreenShot()
    Try
        Dim maxHeight As Integer = 0
        Dim maxWidth As Integer = 0
        For Each scr As Screen In Screen.AllScreens
            maxWidth += scr.Bounds.Width
            If scr.Bounds.Height > maxHeight Then maxHeight = scr.Bounds.Height
        Next
        Dim allScreensCapture As New Bitmap(maxWidth, maxHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
        Dim screenGrab As Bitmap = Nothing
        Dim screenSize As Size = Nothing
        Dim g As Graphics = Nothing
        Dim g2 As Graphics = Graphics.FromImage(allScreensCapture)
        Dim a As New Point(0, 0)
        For Each scr As Screen In Screen.AllScreens
            screenSize = New Size(scr.Bounds.Width, scr.Bounds.Height)
            screenGrab = New Bitmap(scr.Bounds.Width, scr.Bounds.Height)
            g = Graphics.FromImage(screenGrab)
            g.CopyFromScreen(a, New Point(0, 0), screenSize)
            g2.DrawImage(screenGrab, a)
            a.X += scr.Bounds.Width
        Next
        allScreensCapture.Save(strPath, System.Drawing.Imaging.ImageFormat.Jpeg)
        g.Dispose()
        Return True
    Catch ex As Exception
        Return False
    End Try
    strPath = Nothing
End Function
Private Sub OutlookEmail()
    'Create the outlook email, attach the screenshot and present the email to the user to send
    Dim m_email As New Microsoft.Office.Interop.Outlook.Application
    Dim m_message As Microsoft.Office.Interop.Outlook.MailItem = m_email.CreateItem(Interop.Outlook.OlItemType.olMailItem)
    m_message.To = "test@test.co.uk"
    m_message.Subject = "Screenshot of problem attached from " & System.Environment.UserName
    m_message.Attachments.Add(strPath)
    'display the email - dont just send it!
    m_message.Display(m_email)
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
    'The click method for the systray icon
    Main()
End Sub


The application runs from the system tray and a clickevent handler for the notifyicon control calls the Main() sub. The code calls OutlookEmail() which creates a new outlook mail object.

The problem is that each time the notifyicon in the system tray is clicked the memory in use jumps up incrementally - about 3mb each time. I cant for the life of me find what is causing this.

Hope you can help.
AnswerRe: Memory leak in VB.NET screenshot application Pin
Dave Kreskowiak6-Oct-09 4:39
mveDave Kreskowiak6-Oct-09 4:39 
GeneralRe: Memory leak in VB.NET screenshot application Pin
Jordan19826-Oct-09 5:00
Jordan19826-Oct-09 5:00 
AnswerRe: Memory leak in VB.NET screenshot application Pin
Luc Pattyn6-Oct-09 5:39
sitebuilderLuc Pattyn6-Oct-09 5:39 
Questioncopy functionality does not work in CrystalReportViewer Pin
maryam.saboor6-Oct-09 1:02
professionalmaryam.saboor6-Oct-09 1:02 
QuestionBroken Clipping Region Pin
RichardM15-Oct-09 15:26
RichardM15-Oct-09 15:26 
QuestionCustom file format - how to let Windows recognize properties like labels? Pin
pimb24-Oct-09 8:45
pimb24-Oct-09 8:45 
AnswerRe: Custom file format - how to let Windows recognize properties like labels? Pin
Richard MacCutchan5-Oct-09 1:01
mveRichard MacCutchan5-Oct-09 1:01 
GeneralRe: Custom file format - how to let Windows recognize properties like labels? Pin
pimb25-Oct-09 5:17
pimb25-Oct-09 5:17 
GeneralRe: Custom file format - how to let Windows recognize properties like labels? Pin
Richard MacCutchan5-Oct-09 6:25
mveRichard MacCutchan5-Oct-09 6:25 
GeneralRe: Custom file format - how to let Windows recognize properties like labels? Pin
pimb25-Oct-09 6:30
pimb25-Oct-09 6:30 
AnswerRe: Custom file format - how to let Windows recognize properties like labels? Pin
Richard MacCutchan5-Oct-09 7:22
mveRichard MacCutchan5-Oct-09 7:22 
GeneralRe: Custom file format - how to let Windows recognize properties like labels? Pin
Richard MacCutchan7-Oct-09 0:49
mveRichard MacCutchan7-Oct-09 0:49 
GeneralRe: Custom file format - how to let Windows recognize properties like labels? Pin
pimb214-Oct-09 2:52
pimb214-Oct-09 2:52 
GeneralRe: Custom file format - how to let Windows recognize properties like labels? Pin
Richard MacCutchan14-Oct-09 3:01
mveRichard MacCutchan14-Oct-09 3:01 
QuestionBindingSource Insert problem .... Pin
devboycpp3-Oct-09 22:19
devboycpp3-Oct-09 22:19 
QuestionWhy does my visual studio 2008 give me an error of "XMAL editor missing" when I try to use designer in WPF Pin
havegunwilltravel3-Oct-09 9:27
havegunwilltravel3-Oct-09 9:27 
AnswerRe: Why does my visual studio 2008 give me an error of "XMAL editor missing" when I try to use designer in WPF Pin
havegunwilltravel3-Oct-09 9:35
havegunwilltravel3-Oct-09 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.